public void saveImage(byte[] image, int patient_id, MySqlConnection con)
{
string sql = "select * from patient where id ="+patient_id;
DataSet ds = new DataSet("patient");
MySqlDataAdapter dAdapter = new MySqlDataAdapter(sql, con);
MySqlCommandBuilder builder = new MySqlCommandBuilder(dAdapter);
dAdapter.Fill(ds, "patient2");
try
{
ds.Tables["patient2"].Rows[0]["picture"] = image;
dAdapter.Update(ds, "patient2");
// ds.Tables["patient2"].Rows[0].AcceptChanges();
con.Close();
con.Open();
}
catch (Exception exs)
{
Console.WriteLine(exs.Message);
}
}
我该如何修复这个错误...执行此操作后,以下查询都将不起作用...发生了什么?我已经尝试过以任何方式评论“con.close”和“con.open”,...
最佳答案
我怀疑发生这种情况是因为您关闭了连接,然后重新打开它。你不应该重新打开一个关闭的连接......实际上我很惊讶它没有抛出 InvalidOperationException
。无论如何,如果您的方法接收一个打开的连接作为参数,它不应该关闭它。打开连接的代码负责关闭它。
关于c# - 不知何故MySQL在运行后突然无法执行查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7948509/