Problem in updating the database table rows using the datagridview

madhugp

Member
Joined
Nov 27, 2017
Messages
20
Programming Experience
5-10
plz give solution for the problem with with following code written in a button.
the purpose is updating the database table with the contents of each row in the datagridview control.
the problem is only one row is getting updated in database table even i updated many rows.


con = new SqlConnection(str);
con.Open();

foreach (DataGridViewRow row in dataGridView1.Rows)


{

cmd = new SqlCommand("UPDATE scan_rmfb_temp SET product = @prod Where id = '" + dataGridiview1.CurrentRow.Cells[0].Value.ToString() + "' ", con);

cmd.Parameters.AddWithValue("@prod",dataGridView1.CurrentRow.Cells[5].Value.ToString());

cmd.ExecuteNonQuery();

}

thanks and regards

madhu
 
Why do you refer to CurrentRow in the loop? Only one row can be the CurrentRow. Shouldn't you be using the 'row' loop variable instead?
 
Back
Top Bottom