System.Data.SqlClient Namespace SqlCommand Class
Sets or retrieves the Transact-SQL statement or stored procedure to execute at the
data source.
Script |
SqlCommand.CommandText [ = strCommand ] |
strCommand |
The Transact-SQL statement or stored procedure to execute. |
The property is read/write with no default value.
IDbCommand.CommandText
When the CommandType property is set to StoredProcedure, the CommandText property should be set to the name of the stored procedure. The command executes this stored procedure when you call one of the Execute methods.
The SQL Server.NET Data Provider does not support the question mark ( ? ) placeholder for passing parameters to an SQL Statement or a stored procedure called by a Command of CommandType.Text. In this case, named parameters must be used. For example:
SELECT * FROM Customers WHERE CustomerID = @CustomerID
For more information see Using Stored Procedures with a Command.
The following example illustrates how the CommandText property can be set.
void setSqlCommand ( ) {
SqlCommand myCommand = new SqlCommand ( );
myCommand.CommandText = "SELECT * FROM Categories ORDER BY CategoryID";
myCommand.CommandTimeout = 15;
}
Public Sub setSqlCommand ( )
Dim myCommand As New SqlCommand ( )
myCommand.CommandText = "SELECT * FROM Categories ORDER BY CategoryID"
myCommand.CommandTimeout = 15
End Sub |
|
C# |
VB |
SqlCommand Members Connection CommandTimeout CommandType