Command.ExecuteNonQuery()总是返回-1 [英] Command.ExecuteNonQuery() return always -1
问题描述
我有,当我使用的ExecuteNonQuery()方法,在C#中执行命令中选择一个问题;它总是返回-1;这意味着,没有被选择的语句返回的记录,不是吗?
I have a problem when I executed Select command in C# using ExecuteNonQuery() method; It always return -1; This means that no record returned by the selected statement, doesn't it?
但是当我打开SQL同治工作室并运行相同的select语句;我发现,它返回的行。
But when i open sql managment studio and run the same select statement; I found that it returned rows.
请帮帮我!
推荐答案
您不应该执行用的ExecuteNonQuery选择()
。这就是所谓的ExecuteNonQuery,因为你想要的东西来执行这不是一个查询。 A SELECT
是一个查询。你想的ExecuteReader。如果你想要做一个更新
或删除
,那么你可以做一个的ExecuteNonQuery()
,并且会显示多少行受到影响。
You shouldn't execute a SELECT with an ExecuteNonQuery()
. It is called ExecuteNonQuery because you want something to execute that is not a query. A SELECT
is a query. You want to ExecuteReader. If you want to do an UPDATE
or DELETE
, then you can do an ExecuteNonQuery()
and that will show how many rows were affected.
这篇关于Command.ExecuteNonQuery()总是返回-1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!