Subtracting Stocks from DataGridView to MySQL DB (VB.net)

Viewed 17

I am asking for your help. I'm currently developing a Inventory System.

I want to subtract the stocks from the DataGrid view to the target DB. Please see my code and screenshots below for your reference. It works on the current selected row but on the second row, it doesn't do anything.

Sub ReleaseStock()
    Using con = New MySqlConnection(str)
        Try
            con.Open()
            Dim sql As String = "UPDATE tbl_masterinventory SET itemQuantity=itemQuantity - @itemQuantity WHERE itemName=@itemName"
            com = New MySqlCommand(sql, con)
            Dim current_row As Integer = dgvItemSummaryTable.CurrentRow.Index
                com.Parameters.AddWithValue("itemName", dgvItemSummaryTable(1, current_row).Value.ToString)
            com.Parameters.AddWithValue("itemQuantity", dgvItemSummaryTable(4, current_row).Value.ToString)
            com.ExecuteNonQuery()
        Catch ex As Exception
            MsgBox(ex.ToString)
        Finally
            con.Dispose()
        End Try
    End Using
End Sub

Here is the Screenshot of my DGV. enter image description here

0 Answers
Related