asp.net.ph

SqlCommand.CommandText Property

System.Data.SqlClient Namespace   SqlCommand Class


Sets or retrieves the Transact-SQL statement or stored procedure to execute at the data source.

Syntax


Script SqlCommand.CommandText [ = strCommand ]

Property Value


strCommand The Transact-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.

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.

Example

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

See Also

SqlCommand 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