Using System;
Using System. Data;
Namespace Com. CUC. Wu. Example
{
Public Class Class1
{
// For SQL Server, the isolation level of a connection-related transaction is
// Repeatable read or serializable. For Oracle, use select for update in command.
Public Void Lockedsqldatarow ()
{
Dataset DS = New Dataset ();
Sqlconnection sconn = New Sqlconnection ( " Server = localhost; uid = sa; Pwd = sa; database = pubs " );
Sconn. open ();
Sqltransaction TX = New Sconn. begintransaction (isolationlevel. serializable );
Sqlcommand cmd = New Sqlcommand ( " Select * from authors " , Conn, TX );
Sqldataadapter da = New Sqldataadapter (CMD );
Da. Fill (DS, " Autors " );
// Rows locked here
DS. Tables [ 0 ]. Rows [ 1 ] [ 2 ] = " Free " ;
Sqlcommandbuilder BLD = New Sqlcommandbuilder (DA );
Da. Update (DS, " Authors " );
TX. Commit ();
// Rows unlocked here
Da. Dispose ();
Conn. Close (); // Please refer to **í · å × ê ô'
}
Public Void Lockedoradatarow ()
{
Dataset DS = New Dataset ();
Oledbconnection oconn = New Oledbconnection ( " Provider = msdaora; Data Source = ocr11; user id = Scott; Password = Tiger " );
Conn. open ();
Oledbtransaction TX = Oconn. begintransaction ();
Oledbcommand cmd = New Oledbcommand ( " Select * Form EMP for update " , Conn, TX );
Oledbdataadapter da = New Oledbdataadapter (CMD );
Da. Fill (DS, " EMP " );
// Rows locked here;
DS. Tables [ 0 ]. Rows [ 9 ] [ 2 ] = " Clerk " ;
Oledbcommandbuilder BLD = New Oledbcommandbuilder (DA );
Da. Update (DS, " EMP " );
TX. Commit ();
// Rows unlocked here
Da. Dispose ();
Oconn. Close ();
}
} ;
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.