以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  求大师指点“索引超出数组界限”  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=50898)

--  作者:L88919138
--  发布时间:2014/5/15 9:54:00
--  求大师指点“索引超出数组界限”

输入以下代码,想让存货流水账最后一行余额与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


--  作者:Bin
--  发布时间:2014/5/15 10:06:00
--  
建议您用这个方法:
http://www.foxtable.com/help/topics/1485.htm

先找出是哪一行出错,然后分析原因,搞不定,告诉我们运行到哪一行出错,以及错误提示。

--  作者:L88919138
--  发布时间:2014/5/15 10:16:00
--  
这段代码之前运行一段时间并不提示错误,今天点击下才发现有提示这个错误,只是这个错误提示是什么意思还没弄明白,求大师指点下?
--  作者:有点甜
--  发布时间:2014/5/15 10:21:00
--  

没有查到数据,数据表没有一行数据,就会出错

 

            DataTables("存货账").LoadFilter = "[商品名称] = \'" & dr("存货名称") & "\' AND 业务发生日期 is not null"
            DataTables("存货账").Load
            With DataTables("存货账")
                .DataCols("进库").RaiseDataColChanged(.DataRows(0))
            End With


--  作者:L88919138
--  发布时间:2014/5/15 12:52:00
--  

经检测还真如甜大师所说,

“没有查到数据,数据表没有一行数据,就会出错。”那数据没有没被加载进来

判断代码又如何写呢?还请大师赐教?

 

DataTables("存货账").LoadFilter = "[商品名称] = \'" & dr("存货名称") & "\' AND 业务发生日期 is not null"
            DataTables("存货账").Load


--  作者:Bin
--  发布时间:2014/5/15 14:03:00
--  
if DataTables("存货账").datarows.count >0 then
--  作者:L88919138
--  发布时间:2014/5/15 14:15:00
--  

谢谢大师指点。