程序聚合总计。 for循环不从数据库中删除正确数量的项目

时间:2014-05-07 16:52:56

标签: vb.net sql-server-ce

我已经编写了以下过程来更新数据网格中表格中的项目数。我正在使用sqlCE。这是程序:

    Public Sub removeItemsFromDatabase()

    Dim dtCountInventory As New InventoryDataSetTableAdapters.ItemInventoryControlTableAdapter
    Dim strItemName As String = String.Empty
    Dim intQty As Integer

    'Store each selected record on string collection
    For Each row As DataGridViewRow In frmPlaceOrder.grdNewInvoice.Rows

        strItemName = CStr(row.Cells(0).Value())
        intQty = CInt(row.Cells(1).Value)

        dtCountInventory.UpdateItemQuantity(CInt(intQty), strItemName)

    Next

End Sub

以下是查询:

UPDATE       ItemInventoryControl
SET          Stocks = Stocks - @Stocks
WHERE        (ItemName = @ItemName)

这是我的datagrid的样子:

enter image description here

我的程序工作应该按照数据网格中的数量输入的数量更新我的表。它会这样做,但不是按所选金额更新每个项目,而是将两个项目数量相加,然后按该数字进行更新。换句话说,在上图中,不是删除1个蓝月亮和1个Reisling,而是删除每个中的2个。

我尝试过只使用了1个项目并且工作正常,问题是每当我有超过1项时。

0 个答案:

没有答案