I'm trying to insert a DataTable into SQLite table, and i'm using foreach
loop for this, but it throw error SQLiteException: 'database is locked.
i tried to googling about this, and try to dispose my connection with using
Here's my code
public void Insert_to_db(DataTable data)
{
foreach (DataRow row in data.Rows)
{
string alertTag = row["Alert Tag"].ToString();
int group = Convert.ToInt32(row["Group"]);
int line = Convert.ToInt32(row["Line"]);
int task = Convert.ToInt32(row["Task"]);
string sql = string.Format("insert into alert_tag (alert_tag, layer_group, line, task) values ('{0}','{1}','{2}','{3}')", alertTag, group, line, task);
using (SQLiteConnection dbConn = new SQLiteConnection(Tools.SqliteConnString()))
{
using (SQLiteCommand command = new SQLiteCommand(sql, dbConn))
{
dbConn.Open();
command.ExecuteNonQuery();
dbConn.Close();
}
}
}
}