以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  代码求助  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=127667)

--  作者:304376480
--  发布时间:2018/11/19 17:16:00
--  代码求助
老师您好!

在筛选的时候,如果表是空的就会报错:

指定的参数已超出有效值的范围。
参数名: Cannot find column \'_SortKey\'.


(上面是 Filter 代码都正常显示)

Tables("出入库明细").Filter = Filter

\'此前余额
Dim dr As DataRow
Dim mr As Row = Tables("出入库明细").Rows(0)   (问题可能出在此行,因为空表中没有此行存在)
dr = DataTables("出入库明细").Find("[_SortKey] < " & mr("_SortKey") & " And [仓库] = \'" & mr("仓库") & "\'  And [产品ID] = \'" & mr("产品ID") & "\'  ", "[_SortKey] Desc")
If dr IsNot Nothing  Then
e.Form.Controls("NumericComboBox1").value = dr("库存")
Else
e.Form.Controls("NumericComboBox1").value = Nothing
End If



--  作者:有点甜
--  发布时间:2018/11/19 17:29:00
--  

改成

 

If Tables("出入库明细").Rows.count > 0 Then
    Dim dr As DataRow
    Dim mr As Row = Tables("出入库明细").Rows(0)   (问题可能出在此行,因为空表中没有此行存在)
    dr = DataTables("出入库明细").Find("[_SortKey] < " & mr("_SortKey") & " And [仓库] = \'" & mr("仓库") & "\'  And [产品ID] = \'" & mr("产品ID") & "\'  ", "[_SortKey] Desc")
    If dr IsNot Nothing  Then
        e.Form.Controls("NumericComboBox1").value = dr("库存")
    Else
        e.Form.Controls("NumericComboBox1").value = Nothing
    End If
End If


--  作者:304376480
--  发布时间:2018/11/19 19:52:00
--  
好了,一切正常了,谢谢!