title: how to update the qty column in datagridview in c#
body: <p>How do I update the qty column in <code>datagridview</code> in C#? When I call this function only one column has been updated. I couldn't update more than one column.</p>
  
  <p>I attached the image below. What was the problem really I got? There is a column which is named qty, you can see on the <code>datagridview</code>. When I call <code>update()</code> function one one qty column only update. I want to update all qty which entered in the <code>datagridview</code></p>
  
  <p><a href="https://i.stack.imgur.com/huUcF.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/huUcF.jpg" alt="enter image description here"></a></p>
  
  <pre><code>public void updatedb()
  {
      for (int row = 0; row &lt; 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();
  }
  </code></pre>