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