代码如下:
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() 执行到这行代码的时候提示"未将对象引用设置到对象的事例"这里是怎么回事,还望老师的指导