The error is
{Additional information: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1}
This is the code:
for (int i = 0; i < dataGridView2.Rows.Count; i++)
{
StrQuery = "INSERT INTO 'branch1_orders' VALUES ("
+ order_num + ","
+ dataGridView2.Rows[i].Cells["number"].Value + ","
+ dataGridView2.Rows[i].Cells["price"].Value + ");";
command.CommandText = StrQuery;
command.ExecuteNonQuery(); //the error
}
The problem was in the loop it do one more step because the datagradview add a row by it self
the code will be
for (int i = 0; i < (dataGridView2.Rows.Count)-1; i++)
{
StrQuery = "insert into branch1_orders values("
+ order_num + ","
+ dataGridView2.Rows[i].Cells["number"].Value + ","
+ dataGridView2.Rows[i].Cells["price"].Value + ")";
command.CommandText = StrQuery;
command.ExecuteNonQuery();
try
{
command.ExecuteNonQuery();
}
catch (MySql.Data.MySqlClient.MySqlException e2)
{
MessageBox.Show(e2.Message);
}
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments