如何批量插入到MySQL使用C# [英] How to bulk insert into MySQL using C#
问题描述
我以前使用SqlBulkCopy类将数据加载到一个MS SQL Server数据库。结果非常好,正是曾作为我想要它。
I have previously used the SQLBulkCopy class to load data into a MS SQL Server db. The results were very good, and worked exactly as I intended it to.
现在,我试图用一个脚本任务在SSIS中批量加载数据到MySQL使用(5.5.8)数据库或者ODBC或ADO.NET连接(建议?)。
Now, I'm trying to use a script task in SSIS to bulk load data into a MySQL (5.5.8) database using either an ODBC or ADO.NET connection (recommend?).
在我的数据集的列对应与MySQL表的列。什么是做一个数据集的批量插入到一个MySQL数据库的最好方法是什么?
The columns in my dataset correspond with the columns of the MySQL table. What is the best way to do a bulk insert of a dataset into a MySQL database?
推荐答案
您可以使用附带的MySqlBulkLoader MySQL连接器为.NET:
You can use the MySqlBulkLoader shipped with the MySQL Connector for .NET:
var bl = new MySqlBulkLoader(connection);
bl.TableName = "mytable";
bl.FieldTerminator = ",";
bl.LineTerminator = "\r\n";
bl.FileName = "myfileformytable.csv";
bl.NumberOfLinesToSkip = 1;
var inserted = bl.Load();
Debug.Print(inserted + " rows inserted.");
这篇关于如何批量插入到MySQL使用C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!