Error “There is already an open DataReader associated with this Command which must be closed first” when using 2 distinct commands

后端 未结 7 1715
春和景丽
春和景丽 2020-11-29 01:23

I have this legacy code :

 private void conecta()
 {  
     if (conexao.State == ConnectionState.Closed)
         conexao.Open();
 }

 public List

        
7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-29 01:43

    I suggest creating an additional connection for the second command, would solve it. Try to combine both queries in one query. Create a subquery for the count.

    while (dr3.Read())
    {
        dados_historico[4] = dr3["QT"].ToString(); //quantidade de emails lidos naquela verificação
    }
    

    Why override the same value again and again?

    if (dr3.Read())
    {
        dados_historico[4] = dr3["QT"].ToString(); //quantidade de emails lidos naquela verificação
    }
    

    Would be enough.

提交回复
热议问题