以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  请教老师代码中错误问题  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=43243)

--  作者:mamuaiqing
--  发布时间:2013/12/3 1:24:00
--  请教老师代码中错误问题

代码如下:

Dim cmd As New SQLCommand
Dim dd,hd,db As DataTable
cmd.C
cmd.CommandText = "SELECT * From {订单明细} Where [出货] = False And [作废] = False And [编号] > \'\'"
dd = cmd.ExecuteReader
If dd.DataRows.Count > 0 Then
    cmd.CommandText = "SELECT * From {货款单明细} Where [核销] = False And [作废] = False"
    hd = cmd.ExecuteReader
    If hd.DataRows.Count > 0 Then
        Dim hd1 As DataRow
        Dim Cols1() As String = {"数量","计量单位","订单编号","产品名称"}
        Dim Cols2() As String = {"第一列","第二列","第三列","第四列"}
        For Each dr As DataRow In dd.DataRows
            For Each dr1 As DataRow In hd.Select("[订单编号] = \'" & dr("编号") & "\'")
                Dim dr2 As DataRow = db.AddNew()                   执行到这行代码的时候提示"未将对象引用设置到对象的事例"
                For i As Integer = 0 To Cols1.Length -1
                    dr2(Cols2(i)) = dr1(Cols1(i))
                Next
            Next
        Next
    End If
End If

以下为统计代码省略........

 

上面的代码是想实现将订单表跟货款单表的数据加载到各自的DataTable中,再循环两个表中相同编号的数据(货款单中每行数据都记录订单编号),并将货款单中的数据添加到db变量中,最后再获得db中的数据进行相关统计,"Dim dr2 As DataRow = db.AddNew()   执行到这行代码的时候提示"未将对象引用设置到对象的事例"这里是怎么回事,还望老师的指导


--  作者:逛逛
--  发布时间:2013/12/3 7:42:00
--  
你的db 没有实例化,是空的。