C#操作sqlite数据库显示database is locked
王大凤 2018-06-11 08:32:56 代码:
string consql = "Data Source=SHbook.db; Version=3;";
string password = "";
string oldpass = TextBoxOldPass.Text.Trim();
string newpass = TextBoxNewPass.Text.Trim();
using (SQLiteConnection con = new SQLiteConnection(consql))
{
con.Open();
string sql = "select * from [User] where UserName = '" + username + "';";
using (SQLiteCommand com = new SQLiteCommand(sql, con))
{
using (SQLiteDataReader reader = com.ExecuteReader())
{
if (reader.Read())
{
password = reader.GetString(reader.GetOrdinal("Password"));
password = password.Trim();
}
reader.Close();
reader.Dispose();
}
}
con.Close();
}
if (string.Compare(password, oldpass) == 0)
{
//数据库更新语句
using (SQLiteConnection con1 = new SQLiteConnection(consql))
{
con1.Open();
string sql = "update [User] set Password = '" + newpass + "'where UserName ='" + username + "';";
using (SQLiteCommand com1 = new SQLiteCommand(sql, con1))
{
MessageBox.Show("aaa");
int r = com1.ExecuteNonQuery(); 问题是执行到这句出错
MessageBox.Show(Convert.ToString(r));
if (r > 0)
{
MessageBox.Show("999");
if (MessageBox.Show("修改密码成功", "提示", MessageBoxButtons.OK) == DialogResult.OK)
{
this.Close();
}
}
}
}