1、Build()和BuildDataSource只能使用其中一个
2、必须在添加数据前调用Build()或者BuildDataSource
……
dtb.AddDef("异常原因", GetType(String), 50)
With Tables("采购合同数据分析_Table1")
.DataSource = dtb.BuildDataSource()
Dim dt1 As DataTable = DataTables("采购合同管理")
Dim dt2 As DataTable = DataTables("委托支付管理")
Dim dt3 As DataTable = DataTables("进项piao录入")
For Each nm As String In dt1.SQLGetValues("供货方名称", "[项目名称] = '" & txt & "'")
Dim dr As DataRow = DataTables("采购合同数据分析_Table1").AddNew()
dr("供货方名称") = nm
dr("采购合同金额") = dt1.sqlCompute("Sum(采购合同金额)", "[供货方名称] = '" & dr("供货方名称") & "'")
dr("已支付金额") = dt2.sqlCompute("Sum(付款金额)", "[供货方名称] = '" & dr("供货方名称") & "'")
dr("未支付金额") = dr("采购合同金额") - dr("已支付金额")
dr("已开piao金额") = dt3.sqlCompute("Sum(税价合计金额)", "[供货方名称] = '" & dr("供货方名称") & "'")
dr("未开piao金额") = dr("已支付金额") - dr("已开piao金额")
If dr("未开piao金额") < 0 Then
dr("是否异常") = True
dr("异常原因") = "开piao金额大余委托支付金额"
ElseIf dr("未开piao金额") > 0 Then
dr("是否异常") = True
dr("异常原因") = "付款后未收到足额的进项piao"
End If
Next
' MainTable = Tables("统计")
.DataTable.DataCols.Add("序号", GetType(Integer)) '新增序号列
.DataTable.DataCols.Add("备注", GetType(String)) '新增序号列
……