Advanced Usage of SQLServer in ASP.NET

xiaoxiao2021-03-06  67

1. Simple data operations can write a single-strip-band-bearing SQL statement, then use mycm.parameters.add

(

"@ Vname", value) plus parameters,

You can also write a stored procedure, you can pass the parameters or return parameters during the process, so programming more objects.

Return parameters can be obtained

...

VRT = mycm.parameters.add ("ReturnValues", SqldbType.It)

vrt.direction = mycm.parameters.ReturnValus

...

cm.execute nonequery ()

ReturnValue = Mycm.Parameters ("ReturnValues"). Value

'If you are outgoing parameters, use the following syntax:

Vot = mycm.parameters.add ("@ outp", sqldbtype ...)

vot.direction = mycm.parameters.output

... cm.executenoneQuery ()

Otvalue = mycm.parameters

"@Outp"). Value

...

------- Store the following structure

Create Procedur Namep

(@ v1 nvarchar (88),

@mon Money

@Outp nvarchar (..) Output

)

AS

........

Return (Select Count (*) from ....)

- Note: Stored Procedure Return Values ​​can only be used for Integer types, each SQLServer process actually returns a value of 0

2. Use the link to buffer change performance

Add a buffer option in the SQLServer connection string:

Connection Lifetime

CONNECTION ...

...

3. Transaction processing

Transaction processing can be enabled in three ways:

First: Database transaction refers to the transaction in the database end code, such as

Create Product Testtrans

AS

Being transaction

Update Taba Set ...

Update Tabb Set ...

Commit transaction

....

EXCEPTION

Rollback Transaction

....

2: ADO.NET transaction

...

CMA = New Sqlcommand ("", CON)

CMB = New SQLCOMMAND (", CON)

Con.open

ObjTransaction = con.begintransaction

Cma.Transaction = ObjTransaction

CMB.TRANSACTION = ObjTransaction

Try

Cma.exec ....

CMB.exec .....

Objtransaction.commit

Catch exception

Objtransaction.rollback

...

Finally

Con. close ()

....

Three: ASP.NET page transactions

转载请注明原文地址:https://www.9cbs.com/read-89943.html

New Post(0)