简体   繁体   中英

.net c sharp executeScalar() OR executeNonQuery()

我正在运行SP,它不返回任何行或数据,而不是那种效率更高的executeScalar()executeNonQuery()

If you don't want to read a value you should use executeNonQuery. It has nothing to do with efficiency. You should do it because that's the correct way to do it. Using executeScalar here is just wrong.

It's probably also faster, but that's not the point. If you are firing so many queries that this minor performance detail makes a difference something is wrong with your query.

我不确定这两者是否重要,executeNonQuery将在其中完成的对象构造略少,但在大多数情况下差异可以忽略不计。

Executescalar返回一个值,executeNonquery通常用于插入,更新等。在这种情况下,由于您没有返回任何值,您应该使用ExecuteNonQuery。

ExecuteScalar returns a single value as a result of the query in the command object, therefor the other would be better to use. ExecuteNonQuery does not return a value (except rows effected by the query).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM