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 !!!
Pankaj Kumar ChoudharyPosted Jun 5, 2015, 7:54 PM
Manoj BhoirPosted Jun 5, 2015, 1:13 PM
who caresPosted Jun 5, 2015, 10:56 AM
who caresPosted Jun 5, 2015, 10:55 AM
Khargesh RajputPosted Jun 5, 2015, 6:27 AM
Rajeesh MenothPosted Jun 5, 2015, 6:11 AM