ShalithaCell / MySQLBulk-Insert-Update

Improve MySQL bulk data insert and update

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MySQL BulkInsert & BulkUpdate

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.


Purpose

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.


Usage

Generating Data table

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));
}

Import lib

Add Reference to MySQLBulkIU.dll file

using MySQLBulkIU;

Create connection string

string connectionString = "Server=localhost;Database=test;Uid=root;Pwd=1234;";

Bulk Insert

//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");

Bulk Update

//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);

Dependencies

  • MySql.Data.dll

Contribute

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.

About

Improve MySQL bulk data insert and update


Languages

Language:C# 100.0%