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);
}
相關(guān)文章
C# 制作PictureBox圓形頭像框并從數(shù)據(jù)庫中讀取頭像
C#提供的PictureBox控鍵默認情況下是方形的非常大的影響美觀,怎么解決這一問題呢?下面小編給大家?guī)砹薈# 制作PictureBox圓形頭像框并從數(shù)據(jù)庫中讀取頭像的操作代碼,感興趣的朋友一起學習下吧2021-08-08
C# Entity Framework中的IQueryable和IQueryProvider詳解
這篇文章主要介紹了C# Entity Framework中的IQueryable和IQueryProvider詳解,本文使用實例分析這兩個接口的內(nèi)部實現(xiàn),需要的朋友可以參考下2015-01-01

