数据库表已锁定(C#,Sqlite3)

时间:2018-09-12 13:14:58

标签: c# sqlite

SQLiteCommand sqlite_cmd_show;
SQLiteConnection sqlite_conn;
SQLiteDataReader sqlite_datareader;

sqlite_cmd_show = sqlite_conn.CreateCommand();
sqlite_cmd_show.CommandText = "SELECT * FROM stock WHERE item_barcode = @barcode and serial_data != '' and serial_data > @serial";
sqlite_cmd_show.Parameters.Add("@barcode", System.Data.SqlDbType.Int);
sqlite_cmd_show.Parameters.Add("@serial", System.Data.SqlDbType.Int);

for (int count = 0; count < DataGItem.Rows.Count; count++)
{
    isExist = false;

sqlite_cmd_show.Parameters["@barcode"].Value = (String)DataGItem.Rows[count].Cells[1].Value;
sqlite_cmd_show.Parameters["@serial"].Value = (String)DataGItem.Rows[count].Cells[6].Value;

sqlite_datareader = sqlite_cmd_show.ExecuteReader();
while (sqlite_datareader.Read())
{
    isExist = true;
    break;
}

if (isExist)
{
    continue;
}

sqlite_cmd = sqlite_conn.CreateCommand();
sqlite_cmd.CommandText = "Insert into stock ( stock_id, item_barcode ) VALUES ("+ stock_id +",'" + txtDocNo.Text + "')";
sqlite_cmd.ExecuteNonQuery();

这是我的示例代码,其错误在最后一行“ sqlite_cmd.ExecuteNonQuery();”

错误是

SQLite.NET.dll中发生了类型为'Finisar.SQLite.SQLiteException'的未处理异常

其他信息:数据库表已锁定

所以,我试图做很多事情,但这没用

请帮助

1 个答案:

答案 0 :(得分:0)

在插入语句之前关闭连接

sqlite_conn.Close()

然后打开一个新的

sqlite_conn.Open()