Alright so I have part of the script I am writing that will insert new addresses if its already in one table but the issue is i get an exception that I can't seem to fix, I have debugged many times and it says
System.InvalidOperationException: 'There is already an open DataReader associated with this Connection which must be closed first.'
Which I have googled and nothing really helped so here is the code chunk that is giving me the error
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 ");
}