ExecuteNonQuery不返回结果 [英] ExecuteNonQuery doesn't return results

查看:216
本文介绍了ExecuteNonQuery不返回结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的(粗略)代码(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专门用于UPDATEINSERTDELETE查询.根据文档:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆