IDbCommand.CommandText IDbCommand.CommandText IDbCommand.CommandText IDbCommand.CommandText Property

定义

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

public:
 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.

适用于

另请参阅