【发布时间】:2009-09-01 11:39:28
【问题描述】:
在使用类似这样的构造时,我能否避免打开 DataReader 异常(“已经有一个打开的 DataReader 与此命令关联,必须先关闭。”)?
public void FirstMethod()
{
using (var command = connection.CreateCommand())
{
command.CommandText = "...";
using (var reader = command.ExecuteReader())
{
// do something with the data
SecondMethod();
}
}
}
public void SecondMethod()
{
using (var command = connection.CreateCommand())
{
command.CommandText = "...";
using (var reader = command.ExecuteReader()) // Exception
{
}
}
}
最好的问候
【问题讨论】:
标签: c# ado.net datareader