C#/.Net 中快速批量给SQLite数据库插入测试数据
程序员文章站
2024-01-27 21:45:04
使用transaction:
var stopwatch = new stopwatch();
using (var cmd = new sqli...
使用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); }
上一篇: 平安银行推物联网金融,重振银行动产融资
下一篇: ps制作非常漂亮的火红枫叶