漫游到数据库-最佳方法 [英] Rocording to a DB - best approach

查看:91
本文介绍了漫游到数据库-最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我需要向数据库插入大约600万条记录.

I need to insert to a DB about 6 million records.

现在;问题是哪种方法最好:

Now; the question is which approach is best:

1.声明并打开一次连接(在Button Click事件中),使其保持打开状态,并保持插入状态而不会以多线程方式调用类?

1. Declare and open a connection once (in the Button Click event) keep it open and keep inserting from calling a class in a mutithreaded manner ?

2.以多种方式调用一个类(许多线程,每个线程都执行Open-Insert-Close)?

2. Call a class in a multihreaded manner (many threads, each thread doing Open - Insert - Close) ?

哪个会更快,更高效.

亲切的问候

Peter

推荐答案

如果要插入大量数据,可以使用DataTable.

If you want to insert huge data, you can use DataTable.

首先将数据插入到DataTable中(例如,一次记录100k条记录),然后运行"insert into table select xxx from DataTable",这比一张一张地插入数据要快得多.

Insert the data to DataTable first (For example, 100k records one time) and then run "insert into table select xxx from DataTable", this will be much faster than insert data one by one.

谢谢


这篇关于漫游到数据库-最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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