System.Data.SqlClient Namespace SqlCommand Class
Initializes a new instance of the SqlCommand class with the text of the query and an SqlConnection.
[ VB ]
Public Sub New ( _
ByVal cmdText As String, _
ByVal connection As SqlConnection _
)
[ C# ]
public SqlCommand (
string cmdText,
SqlConnection connection
);
[ C++ ]
public: SqlCommand (
String* cmdText,
SqlConnection* connection
);
[ JScript ]
public function SqlCommand (
cmdText : String,
connection : SqlConnection
);
- cmdText
- The text of the query.
- connection
- An SqlConnection that represents the connection to an instance of SQL Server.
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 ( ) {
string query = "SELECT * FROM Categories ORDER BY CategoryID";
string connString =
"uid=sa; pwd=; database=northwind; server=myServer";
SqlConnection myConn = new SqlConnection ( connString );
SqlCommand myCommand = new SqlCommand ( query, myConn );
myCommand.CommandTimeout = 15;
myCommand.CommandType = CommandType.Text;
}
Public Sub setSqlCommand ( )
Dim query As String = "SELECT * FROM Categories ORDER BY CategoryID"
Dim connString As String = _
"uid=sa; pwd=; database=northwind; server=myServer"
Dim myConn As New SqlConnection ( connString )
Dim myCommand As New SqlCommand ( query, myConn )
myCommand.CommandTimeout = 15
myCommand.CommandType = CommandType.Text
End Sub |
|
C# |
VB |
SqlCommand Members SqlCommand Constructor Overload List