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 520祝福语最简短的
13 美人出嫁文案祝福语简短
14 给母校送花祝福语简短
15 领证祝福语高级文案简短
16 发财祝福语长辈的话简短
17 最酷的毕业祝福语简短
18 毕业升高中祝福语简短