How to bulk insert into MySQL using C#
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.
Now, I'm trying to use a script task in SSIS to bulk loa开发者_运维问答d data into a MySQL (5.5.8) database using either an ODBC or ADO.NET connection (recommend?).
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?
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.");
精彩评论