好的,所以我正在编写的脚本的一部分,如果它已经在一个表中,它将插入新地址,但问题是我得到了一个我似乎无法修复的异常,我已经调试了很多次,它说
System.InvalidOperationException: '已经有一个打开的 DataReader 与此 Connection 关联,必须先关闭。'
我用谷歌搜索并没有真正帮助所以这里是给我错误的代码块
try
{
_conn.Open();
string compare =
"SELECT address, COUNT(*) FROM melena_edws m " +
"WHERE EXISTS (SELECT address FROM actuals a WHERE m.address = a.address) " +
"GROUP BY address ";
CtreeSqlCommand cmd = new CtreeSqlCommand(compare, _conn);
CtreeSqlDataReader reader = cmd.ExecuteReader();
int count = (int)cmd.ExecuteScalar();//<------Error is here
if(count > 0)
{
while (reader.Read())
{
Console.WriteLine(string.Format("{0,12}", reader["address"]));
//cmd2.ExecuteNonQuery();
reader.Close();
Compare($"{reader["address"]} ");
}
reader.Dispose();
_conn.Close();
}
else
{
Console.WriteLine("Address already within table");
}
}
catch (CtreeSqlException ctsqlEx)
{
Console.WriteLine(ctsqlEx + " error running command script ");
}