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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Himanshu Gupta86 reputationPosted Oct 8, 2017, 11:42 PM EDT
SandyRank #2,015 · 718 reputationPosted Oct 8, 2017, 11:43 PM EDT
fareed fa32 reputationPosted Oct 9, 2017, 12:14 AM EDT
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();
}
}
}
SandyRank #2,015 · 718 reputationPosted Oct 9, 2017, 1:54 AM EDT
fareed fa32 reputationPosted Oct 9, 2017, 5:04 AM EDT
SandyRank #2,015 · 718 reputationPosted Oct 9, 2017, 5:10 AM EDT
fareed fa32 reputationPosted Oct 9, 2017, 5:31 AM EDT
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();
}
}
SandyRank #2,015 · 718 reputationPosted Oct 9, 2017, 5:37 AM EDT