public void Savetodb (DataTable dt) {/* Todo:sqlite does not provide a mechanism for bulk insertions and requires that all data be updated through a transaction * http://www The. cnblogs.com/hbjohnsan/p/4169612.html * Eorr database is locked and cannot execute its own code. */String CONNSTR = @ "Data source=e:\yqsqlite\yqsqlite\data\yq.db"; using (sqliteconnection conn = new Sqliteconnection (CONNSTR)) {Conn. Open (); using (System.Data.SQLite.SQLiteTransaction trans = conn. BeginTransaction ()) {using (System.Data.SQLite.SQLiteCommand cmd = new Sqlitecommand (CO nn)) {cmd. Transaction = trans; try {foreach (DataRow dr in DT). Rows) {cmd. CommandText = @ "Insert or ignore into RssItem () VALUES (" +int32.parse (dr[0). ToString ()) + ", '" +dr[1]. ToString () +"', '" +dr[2. ToString () + "', '" + dr[3]. ToString () + "', '" + datetime.parse (dr[4). ToString ()) + "', '" +dr[5]. ToString () + "', '" +dr[6]. ToString () + "')"; Cmd. ExecuteNonQuery (); } trans.commit (); } catch (Exception ex) {MessageBox.Show (ex. Message); Trans. Rollback (); } } } } }
SQLite uses transaction update-by command