我的理解应该是同一个产品入库数字相加 - 销售数量 才应该得到可用库存,这样就永远不会错: 按钮事件代码如下:
Dim dr As DataRow
Dim cmd1 As New SQLCommand
Dim dt1 As DataTable
cmd1.CommandText = "SELECT * From {销售表}"
dt1=cmd1.ExecuteReader(True)
Dim cmd As New SQLCommand
Dim dt As DataTable
cmd.CommandText = "SELECT * From {商品入库}"
dt = cmd.ExecuteReader(True)
Dim Arys As List(Of String())
Arys = dt1.GetValues("产品名称|数量")
For Each Ary As String() In Arys
dr= dt.Find("产品名称 ='" & Ary(0) & "'")
If dr IsNot Nothing Then
dr("可用库存")=dt.Compute("Sum(入库数量)","产品名称='" & Ary(0) & "'")-dt1.Compute("Sum(数量)","产品名称='" & Ary(0) & "'")
End If
dt.Save
dr= DataTables("商品入库").Find("产品名称 ='" & Ary(0) & "'")
If dr IsNot Nothing Then
dr.load
End If
Next