who cares

who cares

  • NA
  • 5
  • 987

SQLException Unhandled Syntax error near ')'

Jun 5 2015 5:33 AM
Following is the code snippet i wrote for taking values from all the rows of a dataGridView and insert them into a table. The table name is stored in a string variable  subtable.
 
During debugging an exception occurs at the y.ExecuteNonQuery() line saying:
 
SQLException Unhandled 
 
Syntax error near ')' 
 
x = new SqlConnection("Data Source= AHSUYA ;initial catalog=master;integrated security=sspi;");
x.Open();
for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
{
y = new SqlCommand("Insert into " + subtable + "values(@a,@b,@c)",x);
y.Parameters.AddWithValue("@a", dateTimePicker1.Value.Date.ToShortDateString());
y.Parameters.AddWithValue("@b", dataGridView1.Rows[i].Cells[0].Value.ToString());
y.Parameters.AddWithValue("@c", dataGridView1.Rows[i].Cells[1].Value.ToString());
 
 
y.ExecuteNonQuery();
}
x.Close();
I cannot determine whats wrong with the code ... please help me out !!!

Answers (6)