当使用的ExecuteScalar,的ExecuteReader,的ExecuteNonQuery? [英] When to use ExecuteScalar,ExecuteReader,ExecuteNonQuery?

查看:97
本文介绍了当使用的ExecuteScalar,的ExecuteReader,的ExecuteNonQuery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很困惑,以获得使用





  1. 的ExecuteScalar,

  2. 的ExecuteReader,

  3. 的ExecuteNonQuery




当以使用这些方法?


解决方案

的ExecuteScalar()只返回从第一首列中的值您的查询的行。结果
的ExecuteReader()返回一个对象,它可以遍历整个结果集。结果
的ExecuteNonQuery()不返回数据都:仅受插入,更新行数或删除。



此外,这似乎是一个很好的时间让你熟悉的 MSDN 。这是文档是由为:你有方法名。去看看他们。


I am confused to get the use of

  1. ExecuteScalar,
  2. ExecuteReader,
  3. 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屋!

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