I have 2 queries but on update cmd2.ExecuteNonQuery();
it throws an exception "database is locked":
if (txt_balance.Text != "")
{
using ( SQLiteConnection con = new SQLiteConnection(obj.getDbSourceFile))
{
con.Open();
SQLiteCommand cmd1 = new SQLiteCommand("SELECT [supplier_balance] FROM [s_supplier] where supplier_name='" + comboPurchaseSupplier.Text + "'", con);
SQLiteDataReader DR = cmd1.ExecuteReader();
// hfcconn.Close();
if (DR.HasRows)
{
if (DR.Read())
{
//hfcconn.Open();
using (SQLiteConnection con2 = new SQLiteConnection(obj.getDbSourceFile))
{
SQLiteCommand cmd2 = new SQLiteCommand("update [s_supplier] set supplier_balance=" + (DR.GetInt32(0) + Convert.ToInt32(txt_balance.Text)) + " where supplier_name='" + comboPurchaseSupplier.Text + "'", con2);
con2.Open();
cmd2.ExecuteNonQuery();
DR.Dispose();
// con.Close();
}
}
}
// con.Close();
}
}
The problem is that you are using two connections.
Connections (and their transactions) are isolated from each other, so the second connection cannot update a table on which the first connection still has an open reader.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.