使用像这样的构造时,我可以避免打开 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
{
}
}
}
此致