老师,下面代码总是重复引用。我把他放在项目事件中的 AfterOpenProject
Dim cmd5 As New SQLCommand
Dim dt As DataTable
cmd5.Co nnecti
Dim t5 As Table = Tables("进销存")
Dim filter = iif(t5.filter > "", t5.filter, "1=1")
cmd5.CommandText = "SEL ECT DISTINCT year(日期) as 年, 来源,客户ID,客户名称 from {进销存} where " & filter
dt = cmd5.ExecuteReader()
For Each dr As DataRow In dt.datarows
filter = "年份 = '" & dr("年") & "' and 来源 = '" & dr("来源") & "' and 客户名称 = '" & dr("客户名称") & "'"
Dim ndr As DataRow = DataTables("年度统计").find(filter)
If ndr Is Nothing Then
ndr = DataTables("年度统计").addnew
End If
ndr("年份") = dr("年")
ndr("来源") = dr("来源")
ndr("客户名称") = dr("客户名称")
Next
应该是来源列没有值引起的。参考这里的方法生成查询条件:
http://www.foxtable.com/webhelp/topics/1058.htm
Dim Filter As String
If dr.isnull("年")=false Then
Filter = "年份 = '" & dr("年") & "'"
End If
If dr.isnull("来源")=false Then
If Filter > "" Then
Filter = Filter & " And "
End If
Filter = Filter & "来源 = '" & dr("年") & "'"
End If
……
老师,是来源值是空引起的。下面代码修改不好。
Dim cmd5 As New SQLCommand '年度统计
Dim dt As DataTable
cmd5.C
Dim t5 As Table = Tables("进销存")
Dim filter = iif(t5.filter > "", t5.filter, "1=1")
cmd5.CommandText = "SEL CT DISTINCT year(日期) as 年, 来源,客户ID,客户名称 from {进销存} where " & filter
dt = cmd5.ExecuteReader()
For Each dr As DataRow In dt.datarows
filter = "年份 = '" & dr("年") & "' and 来源 = '" & dr("来源") & "' and 客户名称 = '" & dr("客户名称") & "'"
Dim ndr As DataRow = DataTables("年度统计").find(filter)
If ndr Is Nothing Then
ndr = DataTables("年度统计").addnew
End If
ndr("年份") = dr("年")
ndr("来源") = dr("来源")
ndr("客户名称") = dr("客户名称")
Next
Dim Filter As String
If dr.isnull("年")=False Then
Filter = "年份 = '" & dr("年") & "'"
End If
If dr.isnull("来源")=False Then
If Filter > "" Then
Filter = Filter & " And "
End If
Filter = Filter & "来源 = '" & dr("年") & "'"
End If
For Each dr As DataRow In dt.datarows
Dim Filter As String=""
If dr.isnull("年")=False Then
Filter = "年份 = '" & dr("年") & "'"
End If
If dr.isnull("来源")=False Then
If Filter > "" Then
Filter = Filter & " And "
End If
Filter = Filter & "来源 = '" & dr("年") & "'"
End If
第三个条件参考上面方式自己学着加
Dim ndr As DataRow = DataTables("年度统计").find(filter)
If ndr Is Nothing Then
ndr = DataTables("年度统计").addnew
End If
ndr("年份") = dr("年")
ndr("来源") = dr("来源")
ndr("客户名称") = dr("客户名称")
Next