ExecuteNonQuery不返回结果 [英] ExecuteNonQuery doesn't return results
问题描述
这是我的(粗略)代码(DAL):
This is my (rough) code (DAL):
int i;
// Some other declarations
SqlCommand myCmdObject = new SqlCommand("some query");
conn.open();
i = myCmdObject.ExecuteNonQuery();
conn.close();
问题是:即使我的SELECT
查询中存在一条记录,i
中的值仍为-1
.
The problem is: Even though there is a record present on my SELECT
query, the value in i
remains -1
.
可能是什么问题?
推荐答案
您执行哪种查询?使用ExecuteNonQuery
专门用于UPDATE
,INSERT
和DELETE
查询.根据文档:>
What kind of query do you perform? Using ExecuteNonQuery
is intended for UPDATE
, INSERT
and DELETE
queries. As per the documentation:
对于UPDATE,INSERT和DELETE 语句,返回值为 受行影响的行数 命令.当触发器存在于 插入或更新表时, 返回值包括 受插入或插入影响的行 更新操作和数量 受触发器影响的行或 触发器.对于所有其他类型的 语句,返回值为-1.
For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. When a trigger exists on a table being inserted or updated, the return value includes the number of rows affected by both the insert or update operation and the number of rows affected by the trigger or triggers. For all other types of statements, the return value is -1.
这篇关于ExecuteNonQuery不返回结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!