I have a datagrid and in it I have many rows. I just want to pick up 2 columns from which one row from which one column will search the database for that row with that value and the second column will update that row with the new value. Please help.
My code which is giving a syntax error
Incorrect syntax near the keyword 'VALUES'
my code
{
using (SqlConnection con = new System.Data.SqlClient.SqlConnection("Data Source=rex;Initial Catalog=PersonalDetails;Integrated Security=True"))
{
con.Open();
for (int i = 0; i <= dataGridView2.Rows.Count - 1; i++)
{
String insertData = "UPDATE Test SET AvailableQty = " + "VALUES (@Qty) Where ItemCode = " + "VALUES (@ItemCode) ";
SqlCommand cmd = new SqlCommand(insertData, con);
cmd.Parameters.AddWithValue("@ItemCode", dataGridView2.Rows[i].Cells[0].Value ?? DBNull.Value);
cmd.Parameters.AddWithValue("@Qty", dataGridView2.Rows[i].Cells[4].Value ?? DBNull.Value);
cmd.ExecuteNonQuery();
}
}
}