SqlCommand 的 4个方法

1 :  ExecuteNonQuery()
Executes non-SELECT commands, such as SQL commands that insert,delete, or update records. The returned value indicates the number of rows affected by the command. You can also use ExecuteNonQuery() to
execute data-definition commands that create, alter, or delete database objects (such as tables, indexes, constraints, and so on).

返回值表明多少行受影响

2 : ExecuteScalar()
Executes a SELECT query and returns the value of the first field of the first
row from the rowset generated by the command. This method is usually used when executing an aggregate SELECT command that uses functions such as COUNT() or SUM() to calculate a single value.

只返回第一行第一列

3 : ExecuteReader()
Executes a SELECT query and returns a DataReader object that wraps a
read-only, forward-only cursor.

执行select语句  返回SqlDataReader

4 : ExecuteXmlReader()
Sends the CommandText to the Connection and builds an XmlReader object.

返回XmlReader , 查询xml 字段时用

-------------------------------------------------

1,2,3 Net Framwork 3.5 可用     4 需要 Net Framework 4.0

原文地址:https://www.cnblogs.com/lthxk-yl/p/3368483.html