asp.net.ph

OleDbCommand.CommandText Property

System.Data.OleDb Namespace   OleDbCommand Class


Sets or retrieves the SQL statement or stored procedure to execute against a data source.

Syntax


Script OleDbCommand.CommandText [ = strCommand ]

Property Value


strCommand The SQL statement or stored procedure to execute.

The property is read/write with no default value.

Implements

IDbCommand.CommandText

Remarks

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.

Example

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;
}
  C# VB

See Also

OleDbCommand Members   Connection   CommandTimeout   CommandType Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph