我正在使用sqlite3进行ac#.net4.5 win form application.i观察到,当我在表上使用UPDATE查询时遇到数据库被锁定错误另一方面SELECT查询在同一个表上没有给出任何错误。为什么会这样?
//qryStrUQMFR = "SELECT * FROM loc_table_1 WHERE t_id =@t_id AND mem_id =@mem_id"; qryStrUQMFR = "UPDATE loc_ loc_table_1 SET field1=@field1, field2=@field2, field3 =@field3, field4 =@field4 WHERE t_id =@t_id AND mem_id =@mem_id";
try
{
using (SQLiteConnection conMRN = new SQLiteConnection(connectionString))
{
conMRN.Open();
using (SQLiteTransaction tranMRN = conMRN.BeginTransaction())
{
using (SQLiteCommand cmdMRN = new SQLiteCommand(qryStrUQMFR, conMRN))
{
cmdMRN.Parameters.Add("@t_id", DbType.Int32).Value = t_id;
cmdMRN.Parameters.Add("@mem_id", DbType.Int32).Value = mem_id;
cmdMRN.Parameters.Add("@field1", DbType.Int32).Value = selAns;
cmdMRN.Parameters.Add("@field2", DbType.Int32).Value = qa;
cmdMRN.Parameters.Add("@field3", DbType.Int32).Value = qna;
cmdMRN.Parameters.Add("@field4", DbType.Int32).Value = qm;
cmdMRN.CommandType = CommandType.Text;
using (SQLiteDataReader rdrMRN = cmdMRN.ExecuteReader())
{
if (rdrMRN != null && rdrMRN.Read())
{
//more code here
}
}// reader closed and disposed up here
}// command disposed here
tranMRN.Commit();
}
} //connection closed and disposed here
}
catch (SQLiteException ex)
{
MessageBox.Show("mrn-->" + ex.Message);
}