一段代码,用来填充班组工位的数据,清除班组工位表后,运行填充代码正常,如果不清除表,再执行一次代码,就会出现运行错误提示:无法在 System.Int32 和 System.String 上执行“=”操作。问题出在哪里,任何修改代码来避免出错,请各位老师指教,谢谢!!
Tables("班组工位").AutoSizeCols()
MainTable = Tables("班组工位")
'填充工位ID
Dim f As New Filler
f.SourceTable = DataTables("在线动态") '指定数据来源
f.SourceCols = "位置" '指定数据来源列
f.DataTable = DataTables("班组工位") '指定数据接收表
f.DataCols = "位置" '指定数据接收列
f.ExcludeExistValue = True
f.Fill()
'填充姓名
For Each cl As Col In Tables("班组工位").cols
If cl.name <> "位置" Then
For Each dr As DataRow In DataTables("班组工位").DataRows
If dr.IsNull("位置") Then
dr(cl.name) = Nothing
Else
Dim pr As DataRow = DataTables("在线动态").Find("位置 = '"& dr("位置") &"' And 组别 = '"& Right(cl.Name,2) &"'")
If pr IsNot Nothing Then
dr(cl.name) = pr("姓名")
End If
End If
Next
End If
Next
'判断无小计行增加小计合计行
With Tables("班组工位")
Dim r As Integer
r = .Find("小计", .RowSel + 1, "位置", False, False, True)
If r = - 1 Then '如果没有找到符合条件的行
Dim dr1 As DataRow = DataTables("班组工位").AddNew()
dr1("位置") = "小计"
Dim dr2 As DataRow = DataTables("班组工位").AddNew()
dr2("位置") = "合计"
End If
End With
DataTables("班组工位").Save()
'清除小计和合计
Dim dr3 As DataRow = DataTables("班组工位").Find("位置 = '小计'")
For Each cl As Col In Tables("班组工位").cols
If cl.name <> "位置" Then
dr3(cl.Name) = Nothing
End If
Next
Dim n As Integer = Tables("班组工位").Rows.Count - 1
Tables("班组工位")(n,1) = Nothing
DataTables("班组工位").Save()
'计数
Dim cnt As Integer = 0
For Each cl As Col In Tables("班组工位").cols
If cl.name <> "位置" Then
cnt = cnt + Tables("班组工位").Compute("Count([位置])", cl.Name & " Is Not Null")
End If
Next
'填充小计合计
For Each cl As Col In Tables("班组工位").cols
If cl.name <> "位置" Then
dr3(cl.Name) = CSng(Tables("班组工位").Compute("Count([位置])", cl.Name & " Is Not Null")) &"/"& DataTables("在线动态").Compute("count(姓名)"," 组别 = '"& Right(cl.Name,2) &"'")
End If
Next
Tables("班组工位")(n,1) = CSng(cnt) &"/"& CSng(DataTables("在线动态").Compute("count(姓名)"))
Tables("班组工位").AutoSizeCols()
DataTables("班组工位").Save()
[此贴子已经被作者于2015/4/16 15:30:08编辑过]