Breaking News

Editors Picks

Tuesday, November 8, 2011

bulk upload or insert data into database in mysql


public void Insertbulkdata(DataTable dt, string fileName, string tablename)
    {
        MySql.Data.MySqlClient.MySqlConnection con = new MySql.Data.MySqlClient.MySqlConnection(ConfigurationManager.ConnectionStrings["MySQLConnectionString"].ToString());
        MySql.Data.MySqlClient.MySqlBulkLoader bulkloder = new MySql.Data.MySqlClient.MySqlBulkLoader(con);
        bulkloder.FieldTerminator = "|";
        bulkloder.LineTerminator = @"\n";
        bulkloder.NumberOfLinesToSkip = 1;       
        bulkloder.FileName = @“C:\filename.txt”;
        bulkloder.TableName = tablename;
  try
{
con.Open();
// Upload data from file
int count = bulkloder.Load();
con.Close();

}
catch (Exception ex)
{
}
finally
{
if (System.IO.File.Exists(savefilepath))
{
System.IO.File.Delete(savefilepath);
     }
            }

}

No comments :

Post a Comment

Contact Us

Name

Email *

Message *