C#/.Net 中快速批量给SQLite数据库插入测试数据
使用transaction:
varstopwatch=newStopwatch();
using(varcmd=newSQLiteCommand(db_con))
using(vartransaction=db_con.BeginTransaction())
{
stopwatch.Reset();
stopwatch.Start();
foreach(variteminsorted)
{
sql=string.Format("insertintodb(st1,st2)values('{0}',{1})",item.Key.Replace("'","''"),item.Value);
cmd.CommandText=sql;
cmd.ExecuteNonQuery();
++readCnt;
if(++readCnt%1000000==0)
{
Console.Write("\rDumped{0}lines...",readCnt);
}
}
Console.Write("\rCommitting....");
transaction.Commit();
stopwatch.Stop();
Console.Write("\rDumped{0}linesusing{1}seconds...",readCnt,stopwatch.Elapsed.TotalSeconds);
}
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短