DbCommand.ExecuteNonQuery 方法

定义

当在派生类中重写时,针对连接对象执行 SQL 语句。When overridden in a derived class, executes a SQL statement against a connection object.

public:
 abstract int ExecuteNonQuery();
public abstract int ExecuteNonQuery ();
abstract member ExecuteNonQuery : unit -> int
Public MustOverride Function ExecuteNonQuery () As Integer

返回

Int32

受影响的行数。The number of rows affected.

实现

注解

您可以使用 ExecuteNonQuery 执行目录操作 (例如,查询数据库的结构或创建) 的表等数据库对象,或通过执行 UPDATE、INSERT 或 DELETE 语句来更改数据库中的数据。You can use ExecuteNonQuery to perform catalog operations (for example, querying the structure of a database or creating database objects such as tables), or to change the data in a database by executing UPDATE, INSERT, or DELETE statements.

尽管不 ExecuteNonQuery 会返回任何行,但映射到参数的任何输出参数或返回值都将用数据填充。Although ExecuteNonQuery does not return any rows, any output parameters or return values mapped to parameters are populated with data.

对于 UPDATE、INSERT 和 DELETE 语句,返回值为该命令所影响的行数。For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. 对于其他所有类型的语句,返回值为 -1。For all other types of statements, the return value is -1.

适用于

另请参阅