IDbCommand.CommandText 属性


获取或设置对数据源运行的文本命令。Gets or sets the text command to run against the data source.

 property System::String ^ CommandText { System::String ^ get(); void set(System::String ^ value); };
public string CommandText { get; set; }
member this.CommandText : string with get, set
Public Property CommandText As String



要执行的文本命令。The text command to execute. 默认值为空字符串 ("")。The default value is an empty string ("").


下面的示例创建派生类的实例, OleDbCommand 并设置其一些属性。The following example creates an instance of a derived class, OleDbCommand and sets some of its properties.

public void CreateOleDbCommand()
   OleDbCommand command = new OleDbCommand();
   command.CommandText = "SELECT * FROM Categories ORDER BY CategoryID;";
   command.CommandType = CommandType.Text;
Public Sub CreateOleDbCommand()
    Dim command As New OleDbCommand()
    command.CommandText = "SELECT * FROM Categories ORDER BY CategoryID;"
    command.CommandType = CommandType.Text
End Sub


CommandType 属性设置为时 StoredProcedure ,将属性设置 CommandText 为存储过程的名称。When the CommandType property is set to StoredProcedure, set the CommandText property to the name of the stored procedure. 如果存储过程名称包含任何特殊字符,则可能需要用户使用转义符语法。The user may be required to use escape character syntax if the stored procedure name contains any special characters. 当你调用某一 Execute 方法时,该命令将调用此存储过程。The command will call this stored procedure when you call one of the Execute methods.