I'm trying to insert records into sql database and below is my code for insertion from a button click.
I was not able to insert the records and it is throwing a error all the time when i execute the code.....I know there is something wrong in the code but I;m not sure where the issue occurs.....
The error message is "Incorrect syntax near ','.. "
private void ADD_button_Click(object sender, EventArgs e)
{
try
{
using (SqlConnection con = new SqlConnection(sqlconn))
{
con.Open();
for (int i = 1; i < dataGridView.Rows.Count; i++)
{
string sql = @"INSERT INTO ERSBusinessLogic VALUES ("
+ dataGridView.Rows[i].Cells["ERSBusinessLogic_ID"].Value + ", "
+ dataGridView.Rows[i].Cells["ERSBusinessLogic_Formula"].Value + ", "
+ dataGridView.Rows[i].Cells["ERSBusinessLogic_InputsCount"].Value + ", "
+ dataGridView.Rows[i].Cells["ERSBusinessLogic_Inputs"].Value + ");";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.ExecuteNonQuery();
}
}
}
catch (Exception ex)
{
MessageBox.Show("Error : " + ex.Message);
}
finally
{
con.Close();
}
'" in the insert statement.