已初步实现,老师有没有办法简化代码提高运行效率呢?
当前代码如下:
Dim cmd As New SQLCommand
cmd.Connecti
cmd.CommandText ="Sel ect * From {巡察工作安排}"
Dim dt As DataTable
dt = cmd.ExecuteReader()
Dim Products As List(Of String)
Products = dt.sqlGetValues("巡察对象属性")
Dim time As String =Date.today.Year
Dim y As Integer = time '指定年份
Dim time1 As New Date(y, 1, 1)
Dim time2 As New Date(y, 12, 31)
cmd.CommandText ="Sel ect * From {巡察工作覆盖情况}"
Dim dt1 As DataTable
dt1 = cmd.ExecuteReader(True)
Dim bb As DataRow = dt1.AddNew
Dim yxs As Integer
Dim yxs1 As Integer
Dim bnd As Integer
For Each Product As String In Products
Output.Show(Product)
For Each dc As DataCol In dt1.DataCols
output.show(dc.name)
If dc.name.Contains(Product) Then
If dc.name.Contains(Product & "_应巡数") Then
cmd.CommandText ="Sel ect Count(*) From {巡察对象信息} Where 巡察对象属性 = '" & Product & "'"
If cmd.ExecuteScalar > 0 Then
bb(Product & "_应巡数")=cmd.ExecuteScalar
'cmd.CommandText = "UPD ATE {巡察工作覆盖情况} SET " & Product & "_应巡数" & "= '"& cmd.ExecuteScalar & "'"
'cmd.ExecuteNonQuery()
yxs= yxs + cmd.ExecuteScalar
End If
End If
If dc.name.Contains(Product & "_已巡数") Then
cmd.CommandText ="Sel ect Count(*) From {巡察工作安排} Where 巡察对象属性 = '" & Product & "'"
If cmd.ExecuteScalar > 0 Then
bb(Product & "_已巡数")=cmd.ExecuteScalar
'cmd.CommandText = "UPD ATE {巡察工作覆盖情况} SET " & Product & "_已巡数" & "= '"& cmd.ExecuteScalar & "'"
'cmd.ExecuteNonQuery()
yxs1= yxs1 + cmd.ExecuteScalar
End If
End If
If dc.name.Contains(Product & "_本年度") Then
cmd.CommandText ="Se lect Count(*) From {巡察工作安排} Where 巡察对象属性 = '" & Product & "' and 巡察开始时间 >= '" & time1 & "' And 巡察开始时间 <= '" & time2 & "'"
If cmd.ExecuteScalar > 0 Then
bb(Product & "_本年度")=cmd.ExecuteScalar
'cmd.CommandText = "UP DATE {巡察工作覆盖情况} SET " & Product & "_本年度" & "= '"& cmd.ExecuteScalar & "'"
'cmd.ExecuteNonQuery()
bnd= bnd+ cmd.ExecuteScalar
End If
End If
End If
output.show(yxs)
bb("总计_应巡数")=yxs
bb("总计_已巡数")=yxs1
bb("总计_覆盖率")=bnd
Next
bb.save
Next