C#/.Net 中快速批量给SQLite数据库插入测试数据
作者:junjie 时间:2024-01-27 02:19:36
使用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#,.Net,快速,批量,SQLite,插入,数据


猜你喜欢
史上最全Python文件类型读写库大盘点
2021-01-28 22:08:26
mdf文件和ldf文件导入到sql server 2005实现语句
2024-01-21 14:38:07
Python3基础之输入和输出实例分析
2022-08-05 11:08:09
python flask开发的简单基金查询工具
2023-10-29 21:35:42

SQLite3中文编码 Python的实现
2023-02-03 13:21:38
一文详解kubernetes 中资源分配的那些事
2024-05-22 17:47:57

python机器学习之贝叶斯分类
2023-10-16 00:31:28

实现 Python 脚本生成命令行
2022-08-26 01:05:56
python变量的存储原理详解
2023-03-26 14:46:48

Java通过MyBatis框架对MySQL数据进行增删查改的基本方法
2024-01-17 10:27:12
Python 在 VSCode 中使用 IPython Kernel 的方法详解
2023-07-25 10:10:23

使用Python实现企业微信通知功能案例分析
2022-12-26 05:03:48

Pandas之Dropna滤除缺失数据的实现方法
2022-03-30 03:29:42
python中函数返回多个结果的实例方法
2023-02-27 14:46:50
简单方法实现Vue 无限滚动组件示例
2023-07-02 16:50:14
win2003 mysql单向同步配置步骤[已测]
2024-01-14 18:22:16
在Python3中初学者应会的一些基本的提升效率的小技巧
2022-04-05 12:55:28
js与jquery获取父元素,删除子元素的两种不同方法
2023-10-07 04:08:00
msxml3.dll (0x80070005)拒绝访问 解决方法
2010-03-11 21:26:00
构建Python包的五个简单准则简介
2023-05-06 11:38:10