当使用的ExecuteScalar,的ExecuteReader,的ExecuteNonQuery? [英] When to use ExecuteScalar,ExecuteReader,ExecuteNonQuery?
问题描述
我很困惑,以获得使用
- 的ExecuteScalar,
- 的ExecuteReader,
- 的ExecuteNonQuery
块引用>
当以使用这些方法?
解决方案的ExecuteScalar()只返回从第一首列中的值您的查询的行。结果
的ExecuteReader()返回一个对象,它可以遍历整个结果集。结果
的ExecuteNonQuery()不返回数据都:仅受插入,更新行数或删除。
此外,这似乎是一个很好的时间让你熟悉的 MSDN 。这是文档是由为:你有方法名。去看看他们。
I am confused to get the use of
- ExecuteScalar,
- ExecuteReader,
- ExecuteNonQuery
When to use these methods?
解决方案ExecuteScalar() only returns the value from the first column of the first row of your query.
ExecuteReader() returns an object that can iterate over the entire result set.
ExecuteNonQuery() does not return data at all: only the number of rows affected by an insert, update, or delete.Additionally, this seems like a good time for you to get familiar with MSDN. This is what documentation is made for: you have the method names. Go look them up.
这篇关于当使用的ExecuteScalar,的ExecuteReader,的ExecuteNonQuery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!