System.Data.SqlClient Namespace SqlCommand Class
Initializes a new instance of the SqlCommand class.
1. Initializes a new instance of the SqlCommand class.
2. Initializes a new instance of the SqlCommand class with the text of the query.
3. Initializes a new instance of the SqlCommand class with the text of the query and an SqlConnection.
4. Initializes a new instance of the SqlCommand class with the text of the query, an SqlConnection, and the SqlTransaction.
The following example initializes an SqlCommand and sets some of its properties.
NOTE: This example uses one of the overloaded versions of the SqlCommand constructor. For other examples that may be available, see the individual overload topics.
void setSqlCommand ( ) {
SqlConnection myConn = new SqlConnection (
"uid=sa; pwd=; initial catalog=northwind; data source=myServer" );
myConn.Open ( );
SqlTransaction myTrans = myConn.BeginTransaction ( );
string query = "SELECT * FROM Categories ORDER BY CategoryID";
SqlCommand myCommand = new SqlCommand ( query, myConn,myTrans );
}
Public Sub setSqlCommand ( )
Dim myConn As New SqlConnection _
( "uid=sa; pwd=; initial catalog=northwind; data source=myServer" )
myConn.Open ( )
Dim myTrans As SqlTransaction = myConn.BeginTransaction ( )
Dim query As String = "SELECT * FROM Categories ORDER BY CategoryID"
Dim myCommand As New SqlCommand ( query, myConn, myTrans )
End Sub |
|
C# |
VB |
SqlCommand Members