0
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
    c2.command("insert into facture_haraki values("'
    + dataGridView1.Rows[i].Cells[1].Value.ToString() + "','"
    + dataGridView1.Rows[i].Cells[5].Value.ToString() + "',"
    + Convert.ToDouble(dataGridView1.Rows[i].Cells[6].Value.ToString() + ",'"
    + dataGridView1.Rows[i].Cells[4].Value.ToString()) + "',"
    + Convert.ToDouble(dataGridView1.Rows[i].Cells[2].Value.ToString()) + ","
    + Convert.ToDouble(dataGridView1.Rows[i].Cells[3].Value.ToString()) + ","
    + Convert.ToDouble(dataGridView1.Rows[i].Cells[7].Value.ToString()) + ","
    + (lasttotal * 1500) + ","
    + lasttotal + ","
    + discount + ",'"
    + dataGridView1.Rows[i].Cells[0].Value.ToString() + "',"
    + width + ",'"
    + notes +
    "')");
}

enter image description here

rioV8
  • 24,506
  • 3
  • 32
  • 49
  • 1
    The error suggests that there is some incorrect conversion happening. Ensure that you are passing correct parameters to your `Convert.ToDouble` function or you can use `Double.TryParse` function. – Rahul Sharma Sep 16 '19 at 06:48
  • all are correct and am inserting numbers that why am asking for help :( – Hadi Kassem Sep 16 '19 at 06:50
  • c2.command("insert into facture_haraki values(" + c + "," + custid + ",'" + name + "','" + phone + "','" + address + "','" + date + "','" + dataGridView1.Rows[i].Cells[1].Value.ToString() + "','" ........ code Continues from here @mangusta – Hadi Kassem Sep 16 '19 at 06:53
  • 2
    Sql injection is very strong in this one. https://stackoverflow.com/questions/35163361/how-can-i-add-user-supplied-input-to-an-sql-statement – xdtTransform Sep 16 '19 at 06:58
  • `c2.command("insert into facture_haraki values(" ' + ` -> `c2.command("insert into facture_haraki values(' " + ` – mangusta Sep 16 '19 at 06:59
  • @HadiKassem Well in that case, I would go with `Double.TryParse` function to check if my current input is correctly parsed as required and then based on that condition, I would proceed ahead with my query. – Rahul Sharma Sep 16 '19 at 07:02

2 Answers2

0

Like emangusta mentioned, you have a syntax error which causes the statement to be parsed incorrectly.

Stefan
  • 652
  • 5
  • 19
0

It's solved thanks to

Convert.ToDouble(dataGridView1.Rows[i].Cells[6].Value.ToString() +

missing to close the opened ( in this statement! :D

Alessio Cantarella
  • 5,077
  • 3
  • 27
  • 34