title: multiple datagridview data update to database mysql - vb.net
body: <p>I have created a shopping system with two different interfaces. The admin interface is used to add/update/delete items to the database and the customer interface to purchase products. I have a problem updating the quantity in the admin interface after the user bought the product. The quantity in the admin interface is updated till the value goes negative.</p>
  <p><img src="https://i.stack.imgur.com/KOvh8.png" alt="From admin panel - Before transaction" /></p>
  <p><img src="https://i.stack.imgur.com/48bMY.png" alt="From User panel - Transaction Process" /></p>
  <p><img src="https://i.stack.imgur.com/SoPWW.png" alt="From admin panel - After transaction" /></p>
  <pre class="lang-vb prettyprint-override"><code>Try
      For Each row As DataGridViewRow In formPOS.ProductAddToCartDGV.Rows
          dbconnection()
          sql = &quot;UPDATE products_database SET Product_Quantity = Product_Quantity - @ProductQuantity WHERE Product_Code = @ProductCode;&quot;
          cmd = New MySqlCommand
          With cmd
              .Connection = conn
              .CommandText = sql
              .Parameters.Clear()
              .Parameters.AddWithValue(&quot;@ProductCode&quot;, row.Cells(0).Value)
              .Parameters.AddWithValue(&quot;@ProductQuantity&quot;, row.Cells(3).Value)
              result = .ExecuteNonQuery()
  
              If result = 0 Then
                  MsgBox(&quot;Error in updating stocks&quot;)
              Else
                  MsgBox(&quot;Successfully update stocks&quot;)
              End If
          End With
      Next
  Catch ex As Exception
      MsgBox(ex.Message)
  Finally
      conn.Close()
  End Try
  </code></pre>