Here i'm storing bulk data to database, i got sample code for MSSQL database but i need to store data in mysql database.
how can i store it please help me.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
SandyPosted Oct 9, 2017, 9:37 AM
fareed faPosted Oct 9, 2017, 9:31 AM
new DataColumn("PackOf", typeof(string)),
new DataColumn("Price",typeof(string)) });
StringBuilder sCommand = new StringBuilder("INSERT INTO esugamstock (ProductCode, PackOf,Price) VALUES ");
List
foreach (GridViewRow row in GrvProduct.Rows)
{
Rows.Add(string.Format("('{0}','{1}','{2}')", row.Cells[1].Text, row.Cells[3].Text, row.Cells[4].Text));
string pcode = row.Cells[1].Text;
string pack = row.Cells[3].Text;
string price = row.Cells[4].Text;
dt.Rows.Add(pcode, pack, price);
}
if (Rows.Count > 0)
{
sCommand.Append(string.Join(",", Rows));
sCommand.Append(";");
using (MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["Panel"].ToString()))
{
con.Open();
using (MySqlCommand myCmd = new MySqlCommand(sCommand.ToString(), con))
{
myCmd.CommandType = CommandType.Text;
myCmd.ExecuteNonQuery();
}
con.Close();
}
}
SandyPosted Oct 9, 2017, 9:10 AM
fareed faPosted Oct 9, 2017, 9:04 AM
SandyPosted Oct 9, 2017, 5:54 AM
fareed faPosted Oct 9, 2017, 4:14 AM
new DataColumn("PackOf", typeof(string)),
new DataColumn("Price",typeof(string)) });
foreach (GridViewRow row in GrvProduct.Rows)
{
string pcode = row.Cells[2].Text;
string pack = row.Cells[2].Text;
string price = row.Cells[3].Text;
dt.Rows.Add(pcode, pack, price);
}
if (dt.Rows.Count > 0)
{
string consString = ConfigurationManager.ConnectionStrings["panel"].ConnectionString;
using (MySqlConnection con = new MySqlConnection(consString))
{
using (MySqlBulkLoader sqlBulkCopy = new MySqlBulkLoader(con))
{
//Set the database table name
sqlBulkCopy.TableName = "esugamstock";
//[OPTIONAL]: Map the DataTable columns with that of the database table
sqlBulkCopy.ColumnMappings.Add("ProductCode", "ProductCode");
sqlBulkCopy.ColumnMappings.Add("PackOf", "PackOf");
sqlBulkCopy.ColumnMappings.Add("Price", "Price");
con.Open();
sqlBulkCopy.WriteToServer(dt);
con.Close();
}
}
}
SandyPosted Oct 9, 2017, 3:43 AM
Himanshu GuptaPosted Oct 9, 2017, 3:42 AM