System.Data.OleDb Namespace OleDbCommand Class
Sets or retrieves the SQL statement or stored procedure to execute against a data source.
Script |
OleDbCommand.CommandText [ = strCommand ] |
strCommand |
The 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.
When the CommandType property is set to TableDirect, the CommandText property should be set to the name of the table or tables to be accessed. The user may be required to use escape character syntax if any of the tables named contain any special characters. All rows and columns of the named table or tables will be returned when you call one of the Execute methods.
You cannot set the Connection, CommandType and CommandText properties if the current connection is performing an execute or fetch operation.
The OLE DB .NET Provider does not support named parameters for passing parameters to an SQL Statement or a stored procedure called by an OleDbCommand when CommandType is set to Text. In this case, the question mark ( ? ) placeholder must be used. For example:
SELECT * FROM Customers WHERE CustomerID = ?
As a result, the order in which OleDbParameter objects are added to the OleDbParameterCollection must directly correspond to the position of the question mark placeholder for the parameter.
For more information see Using Stored Procedures with a Command.
The following example illustrates using the CommandText property.
void CommandTextDemo ( ) {
OleDbCommand myCommand = new OleDbCommand ( );
myCommand.CommandText = "SELECT * FROM Categories ORDER BY CategoryID";
myCommand.CommandTimeout = 15;
}
Public Sub CommandTextDemo ( )
Dim myCommand As New OleDbCommand ( )
myCommand.CommandText = "SELECT * FROM Categories ORDER BY CategoryID"
myCommand.CommandTimeout = 15
End Sub |
|
C# |
VB |
OleDbCommand Members Connection CommandTimeout CommandType