C#SQLite批量插入或参数化插入效率 [英] C# SQLite Bulk Insert or Parameterized Insert Efficenecy

查看:118
本文介绍了C#SQLite批量插入或参数化插入效率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要保存到SQLite数据库表的数据表.这是我的困境,我不知道该走哪条路. DataTable最多将包含65,000行和可能的12列.

I have a DataTable which I want to save to a SQLite Database Table. Here is my dilemma, I don't know which way to go. At most the DataTable would contain 65,000 rows and probably 12 columns.

因此,将DataTable保存到CSV文件然后将其批量插入SQLite(我不知道如何做)会更快些,还是遍历所有列创建参数然后循环会更快些?通过数据表中的每一行来检索要插入到数据库表中的信息.

So, would it be faster to save the DataTable to a CSV file and then Bulk Insert it into SQLite (which I have no idea how to do) or would it be faster to loop through all the columns create parameters and then loop through each individual row in the datatable to retrieve the information to insert into the database table.

有没有比我列出的方法更好的方法了?

Is there an even better way than what I have listed?

谢谢, 内森

推荐答案

检查此问题退出.

.Net框架类中有一个SqlBulkCopy,它为批量插入提供功能.不幸的是,仅SQL Server数据库支持它.

There is a SqlBulkCopy in the .Net framework class that provides funcitonality for bulk inserts. Unfortunately it is supported only for SQL Server databases.

但是,调整插入内容中的一些参数会使批量插入操作更快.根据人们的报告,单插条不会对性能造成太大的影响.

However tweaking a few parameters on your inserts will make the bulk insert a lot quicker. From what people are reporting there's not that much of a performance hit with single inserts.

这篇关于C#SQLite批量插入或参数化插入效率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆