i tried below code.but i could add one row record only added in to mysql database. i entered three rows records but only one row records only added.what is the problem of the below code please any one can help me this problem.
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
MySqlCommand cmd = new MySqlCommand();
cmd.Connection = con;
cmd.CommandText = "insert into salesproductnew(salesid,productname,qty,price,grosstotal)values(@salesid,@productname,@qty,@price,@grosstotal)";
cmd.Parameters.AddWithValue("@salesid", lbinvoice.Text);
cmd.Parameters.AddWithValue("@productname", dataGridView1.Rows[i].Cells[2].Value);
cmd.Parameters.AddWithValue("@qty", dataGridView1.Rows[i].Cells[3].Value);
cmd.Parameters.AddWithValue("@price", dataGridView1.Rows[i].Cells[4].Value);
cmd.Parameters.AddWithValue("@grosstotal", dataGridView1.Rows[i].Cells[5].Value);
con.Open(); cmd.ExecuteNonQuery();
MessageBox.Show("Record added ............."); con.Close();

Amit GuptaRank #190 · 12.8K reputationPosted May 3, 2017, 7:57 AM EDT
Kobinath Ram132 reputationPosted May 3, 2017, 9:33 AM EDT
Amit GuptaRank #190 · 12.8K reputationPosted May 3, 2017, 9:44 AM EDT
Rafnas T PRank #280 · 8.8K reputationPosted May 3, 2017, 7:37 PM EDT
Kobinath Ram132 reputationPosted May 3, 2017, 8:02 PM EDT
Karthi KeyanRank #1,926 · 762 reputationPosted May 3, 2017, 8:08 PM EDT
Kobinath Ram132 reputationPosted May 3, 2017, 8:21 PM EDT
Rafnas T PRank #280 · 8.8K reputationPosted May 3, 2017, 8:24 PM EDT
Karthi KeyanRank #1,926 · 762 reputationPosted May 3, 2017, 10:21 PM EDT
Khaja MoizuddinRank #270 · 9.4K reputationPosted May 3, 2017, 9:34 AM EDT
Kobinath Ram132 reputationPosted May 3, 2017, 9:09 PM EDT
Rafnas T PRank #280 · 8.8K reputationPosted May 3, 2017, 9:19 PM EDT
Kobinath Ram132 reputationPosted May 4, 2017, 1:55 AM EDT
Amit GuptaRank #190 · 12.8K reputationPosted May 4, 2017, 2:02 AM EDT
Rafnas T PRank #280 · 8.8K reputationPosted May 4, 2017, 3:31 AM EDT
Kobinath Ram132 reputationPosted May 4, 2017, 3:55 AM EDT
Rafnas T PRank #280 · 8.8K reputationPosted May 4, 2017, 3:58 AM EDT
Bidyasagar MishraRank #766 · 3K reputationPosted May 19, 2017, 5:35 AM EDT