System.Data.SqlClient Namespace SqlCommand Class
Initializes a new instance of the SqlCommand class with the text of the query, an SqlConnection, and the SqlTransaction.
[ VB ]
Public Sub New ( _
ByVal cmdText As String, _
ByVal connection As SqlConnection, _
ByVal transaction As SqlTransaction _
)
[ C# ]
public SqlCommand (
string cmdText,
SqlConnection connection,
SqlTransaction transaction
);
[ C++ ]
public: SqlCommand (
String* cmdText,
SqlConnection* connection,
SqlTransaction* transaction
);
[ JScript ]
public function SqlCommand (
cmdText : String,
connection : SqlConnection,
transaction : SqlTransaction
);
- cmdText
- The text of the query.
- connection
- An SqlConnection that represents the connection to an instance of SQL Server.
- transaction
- The SqlTransaction in which the SqlCommand executes.
The following table shows initial property values for an instance of SqlCommand created with this constructor.
You can change the value for any of these parameter by setting the related
property.
The following example initializes an SqlCommand using this constructor and sets some of its properties.
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 SqlCommand Constructor Overload List