以文本方式查看主题

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

--  作者:xvkewen
--  发布时间:2017/3/29 17:41:00
--  代码异常

各位老师,以下代码是写在Datachanging事件里的,当我编辑“是否完成”列(逻辑列)第一行,系统报错(“调用的目标发生了异常,未将对象引用设置到对象的实例”),但是当第一行有数据时,编辑后面行就没有问题;用Msgbox()分段测试,问题在以下黄色Highlight部分;但我实在找不出原因所在,老师给看看吧~

 

 

 

Dim srs,bw As String   \'定义被更新行的办单号,办房部位;

Dim dr_finished As DataRow         \'定义与当前行最近的,有时间前,后行,和第一行与最后一行;

Dim dr_finishdate As List(of DataRow)  \'定义当前办单,当前工艺部件的工艺总条数集合;

srs =e.DataRow("办单号")

bw = e.DataRow("办房部位")

dr_finished = DataTables("工艺表").Find("是否完成 = \'true\' and 工艺序号< \'" & e.DataRow("工艺序号") & "\' and 办单号 = \'" & e.DataRow("办单号") & "\' and 办房部位 = \'" & e.DataRow("办房部位") & "\'","工艺序号 desc")

If dr_finished IsNot Nothing Then

    dr_finishdate = DataTables("工艺表").Select("是否完成 = \'false\' and 办单号 = \'" & srs & "\' and 办房部位 = \'" & bw & "\'and (工艺序号 > \'" & dr_finished("工艺序号") & "\'and 工艺序号 < \'" & e.DataRow("工艺序号") & "\')","工艺序号")

End If


--  作者:有点色
--  发布时间:2017/3/29 17:55:00
--  

先试试下面这段代码,如果还报错,说明不是这段代码有问题。你肯定有其他代码影响

 

Dim srs,bw As String   \'定义被更新行的办单号,办房部位;

Dim dr_finished As DataRow         \'定义与当前行最近的,有时间前,后行,和第一行与最后一行;

Dim dr_finishdate As List(of DataRow)  \'定义当前办单,当前工艺部件的工艺总条数集合;

srs =e.DataRow("办单号")

bw = e.DataRow("办房部位")

dr_finished = DataTables("工艺表").Find("是否完成 = true and 工艺序号< \'" & e.DataRow("工艺序号") & "\' and 办单号 = \'" & e.DataRow("办单号") & "\' and 办房部位 = \'" & e.DataRow("办房部位") & "\'","工艺序号 desc")

If dr_finished IsNot Nothing Then

    dr_finishdate = DataTables("工艺表").Select("是否完成 = false and 办单号 = \'" & srs & "\' and 办房部位 = \'" & bw & "\'and (工艺序号 > \'" & dr_finished("工艺序号") & "\'and 工艺序号 < \'" & e.DataRow("工艺序号") & "\')","工艺序号")

End If