IDbCommand.CommandText 属性

定义

获取或设置对数据源运行的文本命令。

C#
public string CommandText { get; set; }

属性值

要执行的文本命令。 默认值为空字符串 ("")。

示例

以下示例创建派生类的实例, OleDbCommand 并设置其某些属性。

C#
public void CreateOleDbCommand()
{
   OleDbCommand command = new OleDbCommand();
   command.CommandText = "SELECT * FROM Categories ORDER BY CategoryID;";
   command.CommandType = CommandType.Text;
}

注解

当 属性 CommandType 设置为 StoredProcedure时,将 CommandText 属性设置为存储过程的名称。 如果存储过程名称包含任何特殊字符,则用户可能需要使用转义字符语法。 调用其中一个 Execute 方法时,命令将调用此存储过程。

适用于

产品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

另请参阅