Kobinath Ram

Kobinath Ram

  • NA
  • 130
  • 0

how to update the qty column in datagridview in c#.

May 1 2017 9:42 AM
 
 when i call this function only one colum has been updated couln't updated more than one colum
please help me 
 
 public void updatedb()
{
for (int row = 0; row < dataGridView1.Rows.Count - 1; row++)
{
string itmno = dataGridView1.Rows[row].Cells[1].Value.ToString();
string itmqty = dataGridView1.Rows[row].Cells[3].Value.ToString();
// string t = "select * from products where id=" + itmno + "";
// Connnew.DbSearch(t);
con.Close();
MySqlCommand scmd = new MySqlCommand();
scmd.Connection = con;
scmd.CommandText = "select * from products where id in" + itmno + "";
con.Open();
MySqlDataReader dr;
dr = scmd.ExecuteReader();
string oldqty = "", newqty = "";
while (dr.Read())
{
oldqty = dr[5].ToString();
newqty = (int.Parse(oldqty) - int.Parse(itmqty)).ToString();
}
string t2 = ("UPDATE products SET qty = '" + newqty + "' WHERE id = '" + itmno + "' ");
con.Close();
con.Open();
MySqlCommand upcmd = new MySqlCommand(t2,con);
upcmd.ExecuteNonQuery();
MessageBox.Show("Updateeeeeeeeeeeeeeeeeeeeee");
}
con.Close();

Answers (4)