当我尝试分配阅读器时,C# 抛出异常:
Invalid operation. The connection is closed
我尝试从返回单个单元格的查询中获取结果,其中包含平均值。cmd 是一个 oraclecomand,我用它来在表中插入一行,到目前为止效果很好。我接下来会看到消息框,然后出现异常。
try
{
cmd.ExecuteNonQuery();
MessageBox.Show("Recipe Rated");
OracleCommand cm = new OracleCommand("select round(avg(rating),1) from rates where id_rec = "+id);
OracleDataReader reader = cm.ExecuteReader();
reader.Read();
textBox5.Text =""+reader.GetInt16(0);
}