Sqlconnection
Constructor (the overload is two functions ):
Public sqlconnection ();
Public sqlconnection (string); initialize a connection with a given connection string.
Attribute:. connectionstring
. Connectiontimeout connection failure time
The most important methods are:. open (). Close (). createcommand () returns a command associated with the connection object.
Object.
. Begintransaction () starts Database Transaction (overloaded)
. Begintransaction (string); (STARTS database transactions with the specified transaction name)
. Begintransaction (isolationlevel); (STARTS database transactions at the specified isolation level .)
. Begintransaction (isolationlevel, string); (STARTS database transactions with the specified isolation level and transaction name .)
Note:
(Isolationlevel enumeration)
Begintransaction, commit, and rollback methods.
Sqldatareader: Class
To create a sqldatareader, you must call the executereader method of the sqlcommand object instead of using the constructor.
Attribute: fieldcount: gets the number of columns in the current row (that is, the number of fields)
Hasrows: gets a value indicating whether the sqldatareader contains one or more rows.
Isclosed: gets a value that indicates whether the data reader is disabled.
Recordsaffected: gets the number of rows modified, inserted, or deleted by executing a Transact-SQL statement.
Depth: gets a value that indicates the nested depth of the current row.
Common Methods:
. Close (). getboolean get the Boolean value of the specified Column
. Getbyte (). getchar (). getdatetime (). getdouble ()
. Getname (). getint32 (). getint16 (). getint64 ()
. Getordinal (): obtains the sequence number of a given column name .. Getstring ()
. Getvalue (). Read (). tostring ()
Sqlcommand class:
Properties: commandtext; commandtimeout; commandtype; connection; parameters; transaction
Execute sqltransaction of sqlcommand .);
Constructor: (overload 4)
Sqlcommand (): initializes a new instance of the sqlcommand class.
Sqlcommand (string) initializes a new instance of the sqlcommand class with query text.
Sqlcommand (string, sqlconnection): initializes a new SQL command class with query text and sqlconnection
Example.
Sqlcommand (string, sqlconnection, sqltransaction): query text, a sqlconnection, and
Sqltransaction to initialize a new instance of the sqlcommand class
Method:. executereader (). executenonquery (). executexmlreader (): generates an xmlreader () object.
. Createparameter () creates a new instance of the sqlparameter object.
. Cancel () tries to cancel sqlcommand execution
Sqldataadapter class:
Attribute:
. Deletecommand. insertcommand. selectcommand. updatecommand
Method:
. Fill (dateset) is overloaded
. Fill (datetable)
. Fill (dataset, string );
. Fill (datatable, idatareader );
. Fill (dataset, Int, Int, string );
. Update ()
Sqltransaction class: Transact-SQL transactions processed in the SQL Server database
The application creates a sqltransaction object by calling begintransaction on the sqlconnection object. Pair
The sqltransaction object executes all subsequent operations associated with the transaction (for example, committing or aborting the transaction ).
Property:. connection gets the sqlconnection object associated with the transaction, or if the transaction is no longer valid, it is a null reference.
Method:
. Commit () Commit transaction
. Rollback () roll back the transaction from the pending state .) (Heavy Load 2)
Void rollback (string); rolls back a transaction from the pending state, and specifies the transaction or save point name.
. Save (string savepointname
); Create a save point in the transaction (which can be used to roll back a part of the transaction), and specify the name of the Save point.
Object relationship:
Connection --> command --> dataadapter ---------> dateset --> (.....)
Connection ---> command --> datareader
Connection ---> command (common operations include insert, update, and delete)