Fast way to insert and update a very large list of rows in My SQL using C#
Problem is that large list of data are insert and update operations in My SQL are very slow if you use SqlCommand in the one by one per data.
The purpose of this library is for performing Bulk Inserts and Updates without multiple insert and update statements for a collection of strongly typed queries.
DataTable table = new DataTable();
table.Columns.Add("ID");
table.Columns.Add("Name");
for(int i = 0; i < 100; i++)
{
table.Rows.Add((i+1).ToString(), RandomString(10));
}
Add Reference to MySQLBulkIU.dll file
using MySQLBulkIU;
string connectionString = "Server=localhost;Database=test;Uid=root;Pwd=1234;";
//BulkToMySQL(DataTable dt, string tableName, string ConnectionString)
/* -------------------------key note----------------------------
*
* dt = datatable with values to be updated.
* tableName = Table name to be updated in Database.
* ConnectionString = MySql Connection String
*
* */
bool result = BulkInsert.BulkToMySQL(table, "test_bulk", connectionString);
if (result)
MessageBox.Show("Data Insert Successfully");
//UpdateBulkToMySQL(DataTable dt, string tableName, string valueColumn, string conditionColumn, string ConnectionString)
/* -------------------------key note----------------------------
*
* dt = datatable with values to be updated.
* tableName = Table name to be updated in Database.
* Value_Column = column name to be updated.
* conditionColumn = column name used to write 'WHERE' condition
* ConnectionString= MySQL connection string
* */
bool result = BulkUpdate.UpdateBulkToMySQL(table, "test_bulk", "Name", "ID", connectionString);
- MySql.Data.dll
The best way to contribute is by spreading the word about the library:
- Blog it
- Comment it
- Fork it
- Star it
- Share it
A HUGE THANKS for your help.