2017-10-09 88 views
0

请帮忙。这是我的桌子。添加带回路的listview子项目

ID Item  Qty Added Qty 

1 Ballpen  23  5 

2 Pencil  44  4 

3 Pentelpen 12  5 

我要更新一次的物品,但是当我运行我的程序就变成一样的第一个项目。

例如,当点击保存按钮时,所有项目的数量将是28圆珠笔。

这是我的代码。提前致谢。

   Dim lvitem As Object 
       Dim iCount As Integer 
       Dim iLoop As Integer 
       Dim qty As Double = Val(lvPO.Items(0).SubItems(1).Text) + Val(lvPO.Items(0).SubItems(2).Text) 

       iCount = lvPO.Items.Count() 
       If Not lvPO.Items.Count = 0 Then 
        Do Until iLoop = lvPO.Items.Count 
         lvitem = lvPO.Items.Item(iLoop) 
         With lvitem 
         Call SEDCommand("E", "tbl_item", " qty = '" & qty & "' WHERE itemid ='" & .SubItems(0).text & "'") 
         End With 
         iLoop = iLoop + 1 
         lvitem = Nothing 
        Loop 
        MsgBox("Purchase Order (" & tb_refpo.Text & ") is added in database!", MsgBoxStyle.Information, "SYSTEM") 
        ClearTextBox(Me) 
       End If 
+1

你的代码只计算'qty'的一个值,它使用第一个项目来做到这一点。 – Blackwood

+0

@Blackwood我该如何解决这个问题?希望您能够帮助我。 – Sadnerd

回答

1

正如@Blackwood所说的,你只在循环外计算一次数值,并为每个项目使用相同的值。你想在循环中这样做(并使用更多的VB.NET风格的构造使代码更容易阅读。这不是VB6 :-))

If lvPO.Items.Count <> 0 Then 
     For Each lvitem as ListViewItem in lvPO.Items 
     With lvitem 
      Dim qty As Double = Val(.SubItems(1).Text) + Val(.SubItems(2).Text) 
      SEDCommand("E", "tbl_item", " qty = '" & qty & "' WHERE itemid ='" & .SubItems(0).text & "'") 
     End With 
     Next 
     MsgBox("Purchase Order (" & tb_refpo.Text & ") is added in database!", MsgBoxStyle.Information, "SYSTEM") 
     ClearTextBox(Me) 
    End If 
+0

非常感谢兄弟!上帝祝福你!祝你今天愉快! – Sadnerd