你可以使用2'利用'为SqlConnection和SqlDataReader的声明? [英] Can you use 2 'using' statements for both sqlconnection and sqldatareader?
本文介绍了你可以使用2'利用'为SqlConnection和SqlDataReader的声明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您可以用2'使用'像语句:
Can you use 2 'using' statements like:
using (SqlConnection ..)
{
using(SqlDataReader reader = new SqlDataReader())
{
}
}
我试图做到这一点穿上SqlDataReader的
I'm trying to do this put getting an error on the constructor of the SqlDataReader
推荐答案
SqlDataReader对象没有构造函数。你是通过调用SqlCommand对象的的ExecuteReader
方法返回一个DataReader。
SqlDataReader has no constructor. You are returned a datareader by calling the ExecuteReader
method of a SqlCommand object.
例如。
using (SqlConnection ..)
{
SqlCommand cmd = new SqlCommand(...);
using(SqlDataReader reader = cmd.ExecuteReader()))
{
}
}
这篇关于你可以使用2'利用'为SqlConnection和SqlDataReader的声明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文