using(Sqliteconnection conn =NewSqliteconnection (String.Format ("Data source={0}; Pooling=true", Filename.tostring ()))) { using(Sqlitecommand cmd =NewSqlitecommand ()) {Conn. Open (); Cmd. Connection=Conn; Stopwatch Warch=NewStopwatch (); Warch. Start (); Sqlitetransaction Trans=Conn. BeginTransaction (); Cmd. Transaction=Trans; Try { for(inti =0; i < _datatable.rows.count; i++) {Cmd.commandtext="INSERT INTO Historydata (pointid,pointtype,tempvalue,humivalue,ttime) VALUES (@PointId, @PointType, @TempValue, @ Humivalue, @TTime)"; Cmd. Parameters.Add (NewSqliteparameter ("@PointId", Dbtype.int32)); Cmd. Parameters.Add (NewSqliteparameter ("@PointType", Dbtype.string, -)); Cmd. Parameters.Add (NewSqliteparameter ("@TempValue", dbtype.double)); Cmd. Parameters.Add (NewSqliteparameter ("@HumiValue", dbtype.double)); Cmd. Parameters.Add (NewSqliteparameter ("@TTime", Dbtype.datetime)); Cmd. parameters[0]. Value = _datatable.rows[i]["Pointid"]. ToString (); Cmd. parameters[1]. Value = _datatable.rows[i]["Pointtype"]. ToString (); Cmd. parameters[2]. Value = _datatable.rows[i]["Tempvalue"]. ToString (); Cmd. parameters[3]. Value = _datatable.rows[i]["Humivalue"]. ToString (); Cmd. parameters[4]. Value = _datatable.rows[i]["Ttime"]; Cmd. ExecuteNonQuery (); } trans.commit (); } Catch(Exception) {trans. Rollback (); Throw; } warch. Stop (); MessageBox.Show (string. Format ("{0},{1}", _datatable.rows.count, Warch. Elapsed.tostring ())); } }
To insert a statement in a SQLite database using transaction processing
"SQLite" uses Transact-processed inserts with parameters