输入以下代码,想让存货流水账最后一行余额与SQL统计余额不同时自动重算该商品流水账,现运行提示“索引超出数组界限”,不知是何原因?
Dim cmd As new SQLCommand
cmd.c
Dim jV As Double
For Each dr As DataRow In DataTables("存货档案").DataRows
If dr("存货类别") <> "劳务不删"
dr("主管审核") = "待确认"
cmd.CommandText = "Select top 1 余额 From {存货账} Where 商品名称 = '" & dr("存货名称") & "' order by [_sortkey] desc "
If cmd.CommandText IsNot Nothing
jc = cmd.ExecuteScalar
End If
cmd.CommandText = "Select sum(isnull(进库,0)) - sum(isnull(出库,0)) From {存货账} Where 商品名称 = '" & dr("存货名称") & "' and 业务发生日期 is not null"
If cmd.CommandText IsNot Nothing
jV = cmd.ExecuteScalar
End If
If CStr(JV) <> CStr(JC)
dr("账面数量") = jV
DataTables("存货账").LoadFilter = "[商品名称] = '" & dr("存货名称") & "' AND 业务发生日期 is not null"
DataTables("存货账").Load
With DataTables("存货账")
.DataCols("进库").RaiseDataColChanged(.DataRows(0))
End With
cmd.CommandText = "Select top 1 余额 From {存货账} Where 商品名称 = '" & dr("存货名称") & "' order by [_sortkey] desc "
If cmd.CommandText IsNot Nothing
jc = cmd.ExecuteScalar
If CStr(JV) = CStr(JC)
dr("主管审核") = "已确认"
Else
cmd.CommandText = "Select top 1 余额 From {存货账} Where 商品名称 = '" & dr("存货名称") & "' order by [_Identify] desc "
If cmd.CommandText IsNot Nothing
jc = cmd.ExecuteScalar
If CStr(JV) = CStr(JC)
dr("主管审核") = "已确认"
Else
dr("主管审核") = "未确认"
End If
End If
End If
End If
ElseIf CStr(JV) = CStr(JC)
dr("账面数量") = jV
dr("主管审核") = "已确认"
Else
dr("账面数量") =""
dr("主管审核") = "无数据"
End If
End If
Next