代码简化出错:
将原代码:
If c9 <> Nothing Then
dr("目标2") = DataTables("成绩库").Compute("count(单位)", " " & tj1 & " >= '" & c9 & "' And [部别] = '高理' And [年级] = '" & dr("年级") & "' And [类别] = '" & tjlb & "'")
End If
If c10 <> Nothing Then
dr("目标4") = DataTables("成绩库").Compute("count(单位)", " " & tj1 & " >= '" & c10 & "' And [部别] = '高理' And [年级] = '" & dr("年级") & "' And [类别] = '" & tjlb & "'")
End If
If c11 <> Nothing Then
dr("目标6") = DataTables("成绩库").Compute("count(单位)", " " & tj1 & " >= '" & c11 & "' And [部别] = '高理' And [年级] = '" & dr("年级") & "' And [类别] = '" & tjlb & "'")
End If
If c12 <> Nothing Then
dr("目标8") = DataTables("成绩库").Compute("count(单位)", " 语数外 >= '" & c12 & "' And [部别] = '高理' And [年级] = '" & dr("年级") & "' And [类别] = '" & tjlb & "'")
End If
If c13 <> Nothing Then
dr("目标10") = DataTables("成绩库").Compute("count(单位)", " " & tj1 & " >= '" & c13 & "' And [部别] = '高文' And [年级] = '" & dr("年级") & "' And [类别] = '" & tjlb & "'")
End If
If c14 <> Nothing Then
dr("目标12") = DataTables("成绩库").Compute("count(单位)", " " & tj1 & " >= '" & c14 & "' And [部别] = '高文' And [年级] = '" & dr("年级") & "' And [类别] = '" & tjlb & "'")
End If
If c15 <> Nothing Then
dr("目标14") = DataTables("成绩库").Compute("count(单位)", " " & tj1 & " >= '" & c15 & "' And [部别] = '高文' And [年级] = '" & dr("年级") & "' And [类别] = '" & tjlb & "'")
End If
If c16 <> Nothing Then
dr("目标16") = DataTables("成绩库").Compute("count(单位)", " 语数外 >= '" & c16 & "' And [部别] = '高文' And [年级] = '" & dr("年级") & "' And [类别] = '" & tjlb & "'")
End If
简化成:
Dim ary1() As String = {"目标2","目标4", "目标6", "目标10", "目标12", "目标14"}
Dim ary2() As Double = {c9, c10, c11, c13, c14, c15}
Dim ary3() As Double = {"高理","高理", "高理", "高文", "高文", "高文"}
For i As Integer = 0 To ary1.length-1
If ary2(i) <> Nothing Then
dr(ary1(i)) = DataTables("成绩库").Compute("count(单位)", " " & tj1 & " >= '" & ary2(i) & "' And [部别] = '" & ary3(i) & "' And [年级] = '" & dr("年级") & "' And [类别] = '" & tjlb & "'")
End If
Next
If c12 <> Nothing Then
dr("目标8") = DataTables("成绩库").Compute("count(单位)", " 语数外 >= '" & c12 & "' And [部别] = '高理' And [年级] = '" & dr("年级") & "' And [类别] = '" & tjlb & "'")
End If
If c16 <> Nothing Then
dr("目标16") = DataTables("成绩库").Compute("count(单位)", " 语数外 >= '" & c16 & "' And [部别] = '高文' And [年级] = '" & dr("年级") & "' And [类别] = '" & tjlb & "'")
End If
报错:“从字符串“高理”到类型“Double”的转换无效。”。不知怎么回事?请指教。谢谢!