SqlCommand.CommandText 属性   
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置要在数据源中执行的 Transact-SQL 语句、表名或存储过程。
public:
 virtual property System::String ^ CommandText { System::String ^ get(); void set(System::String ^ value); };
	public override string CommandText { get; set; }
	member this.CommandText : string with get, set
	Public Overrides Property CommandText As String
	属性值
要执行的 Transact-SQL 语句或存储过程。 默认值为一个空字符串。
示例
以下示例创建 并 SqlCommand 设置其一些属性。
// <Snippet1>
using System;
using System.Xml;
using System.Data;
using Microsoft.Data.SqlClient;
using System.Data.Common;
using System.Windows.Forms;
public class Form1 : Form
{
    protected DataSet DataSet1;
    protected DataGrid dataGrid1;
    public void CreateCommand()
    {
        SqlCommand command = new SqlCommand();
        command.CommandText = "SELECT * FROM Categories ORDER BY CategoryID";
        command.CommandTimeout = 15;
        command.CommandType = CommandType.Text;
    }
    // </Snippet1>
}
	注解
当 属性 CommandType 设置为 StoredProcedure时,应将 CommandText 属性设置为存储过程的名称。 如果存储过程名称包含任何特殊字符,则用户可能需要使用转义字符语法。 调用方法之一 Execute 时,命令将执行此存储过程。
Microsoft .NET Framework Data Provider for SQL Server 不支持问号 (?) 占位符将参数传递给 Transact-SQL 语句或由 命令调用的CommandType.Text存储过程。 在这种情况下,必须使用命名参数。 例如:
SELECT * FROM dbo.Customers WHERE CustomerID = @CustomerID
有关详细信息,请参阅 配置参数。