Command的Execute系列方法

(1).如果希望返回数据流,可以使用ExecuteReader方法来返回一个DataReader对象;
(2).对于SQL数据源,如果将CommandText属性置为合法的带有FOR XML子句的T—SQL语句,可以使用SqlCommand对象的ExecuteXmlReader方法返回一个XmlReader对象。
(3).如果希望返回单个值,使用ExecuteScalar方法;
(4).执行没有返回值的SQL语句时,调用ExecuteNonQuary方法。
例如:
1)SqlDataReader dr=sqlcmd.ExecuteReader();

2)sqlcmd.CommandText=”select * from Books for xml auto,xmldata”;
XmlReader xr=sqlcmd.ExecuteXmlReader();

3)Sqlcmd.CommandText=”delete * from Books where Price=10”;
Sqlcmd.ExecuteNonReader();

4)Sqlcmd.CommandText=”select count(*) from Books”;
Sqlcmd.ExecuteScalar();

posted @ 2009-01-04 13:27  xumingming  阅读(953)  评论(1编辑  收藏  举报