C#/.Net 中快速批量給SQLite數(shù)據(jù)庫插入測試數(shù)據(jù)
更新時間:2015年06月16日 10:04:20 投稿:junjie
這篇文章主要介紹了C#/.Net 中快速批量給SQLite數(shù)據(jù)庫插入測試數(shù)據(jù),本文直接給出實例代碼,需要的朋友可以參考下
使用transaction:
var stopwatch = new Stopwatch();
using (var cmd = new SQLiteCommand(db_con))
using (var transaction = db_con.BeginTransaction())
{
stopwatch.Reset();
stopwatch.Start();
foreach (var item in sorted)
{
sql = string.Format("insert into db (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} lines using {1} seconds...", readCnt, stopwatch.Elapsed.TotalSeconds);
}
相關文章
C#獲取微信小程序的云數(shù)據(jù)庫中數(shù)據(jù)的示例代碼
本文主要介紹了C#獲取微信小程序的云數(shù)據(jù)庫中數(shù)據(jù)的示例代碼,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-08-08

