当前位置:编程文档 >> C# >> 创建Command后的一系列Execute方法
首页

创建Command后的一系列Execute方法

所属类别:C#
推荐指数:★★☆
文档人气:8
本周人气:5
发布日期:2008-8-2
1.如果希望返回数据流,可以使用ExecuteReader方法来返回一个DataReader对象;
2.对于SQL数据源,如果将CommandText属性置为合法的带有FOR XML子句的T—SQL语句,可以使用SqlCommand对象的ExecuteXmlReader方法返回一个XmlReader对象。
3.如果希望返回单个值,使用ExecuteScalar方法;
4.执行没有返回值的SQL语句时,调用ExecuteNonQuary方法。
例如:
SqlDataReader dr=sqlcmd.ExecuteReader();

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

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

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

文档说明:

     

相关文档


读取评论列表……