临时表转正表报错,如何处理?
Dim dt1 As fxDataSource
Tables("员工满意度窗口_Table1").DataSource = dt1 '
For Each dr1 As DataRow In Tables("员工满意度窗口_Table1").DataTable.DataRows
Dim dr2 As DataRow = DataTables("员工满意度汇总").AddNew()
For Each dc As DataCol In DataTables("员工满意度汇总").DataCols
dr2(dc.Name) = dr1(dc.name)
Next
Next
此主题相关图片如下:临时表转正表报错.jpg

如果做的是交叉统计,或者是合并统计,看到的是标题名,而不是列名。可以把统计表生成到主表,然后打开表结构看看真正的列名
Dim b As New CrossTableBuilder("统计表1",DataTables("订单"))
b.HGroups.AddDef("客户") '添加客户列用于水平分组
b.VGroups.AddDef("产品") '添加产品列用于垂直分组
b.Totals.AddDef("数量") '添加数量列用于统计
b.Totals.AddDef("金额") '添加数量列用于统计
b.Build '生成统计表
Maintable = Tables("统计表1") '打开生成的统计表
统计结果:

以上面实例,如何将临时改为正表?
先到命令窗口测试,使用4楼的方式生成到主表,就可以看到表结构了
Dim dtb As New DataTableBuilder("统计表1")
dtb.AddDef("部门", GetType(String), 16)
dtb.AddDef("福利待遇满意度_得分", GetType(Double))
dtb.AddDef("福利待遇满意度_份数", GetType(Integer))
dtb.AddDef("福利待遇满意度_平均分", GetType(Double))
dtb.Build()
Dim f As New Filler
f.SourceTable = DataTables("员工满意明细")
f.SourceCols = "部门"
f.DataTable = DataTables("员工满意分析细表")
f.DataCols = "部门"
f.Fill()
Dim b As New CrossTableBuilder("统计表1", DataTables("员工满意明细"))
b.HGroups.AddDef("部门") '
b.VGroups.AddDef("调查项目") '
b.Totals.AddDef("得分") '
b.Totals.AddDef("份数")
b.Totals.AddDef("分值", "平均分")
Dim dict As New Dictionary(Of String, String)
Dim dt As DataTable = DataTables("员工满意明细")
For Each c As Col In Tables("员工满意分析细表").Cols
If c.Caption Like "*_*" Then
dict.Add(c.Caption, c.Name)
End If
Next
For Each r As Row In Tables("员工满意分析细表").Rows
For Each c As Col In Tables("员工满意分析细表").Cols
If c.Caption Like "*_份数" Then
r(c.Name) = dt.GetValues("员工编号", "部门='" & r("部门") & "' and 调查项目='" & c.Caption.Split("_")(0) & "'").count
ElseIf c.Caption Like "*_平均分" Then
Dim cl As String = c.Caption.Split("_")(0)
If r(dict(cl & "_份数")) > 0 Then
r(c.Name) = r(dict(cl & "_得分"))
r(c.Name) = r(dict(cl & "_得分")) / r(dict(cl & "_份数"))
End If
End If
Next
Next
MainTable = Tables("员工满意分析细表")
上面代码执行,有2个问题
问题一:得分没统计出来和平均分为0,这是错,得分和平均分正确计算是有值,如何处理?
问题二:代码执行,窗口自动退出,如何让窗口不自动退出?
调试
For Each r As Row In Tables("员工满意分析细表").Rows
For Each c As Col In Tables("员工满意分析细表").Cols
msgbox(c.Caption & "," & c.Name)
If c.Caption Like "*_份数" Then
msgbox("部门='" & r("部门") & "' and 调查项目='" & c.Caption.Split("_")(0) & "'")
r(c.Name) = dt.GetValues("员工编号", "部门='" & r("部门") & "' and 调查项目='" & c.Caption.Split("_")(0) & "'").count
ElseIf c.Caption Like "*_平均分" Then
Dim cl As String = c.Caption.Split("_")(0)
msgbox("cl=" & cl & ",份数=" & r(dict(cl & "_份数")) & ",得分=" & r(dict(cl & "_得分")) )
If r(dict(cl & "_份数")) > 0 Then
r(c.Name) = r(dict(cl & "_得分"))
r(c.Name) = r(dict(cl & "_得分")) / r(dict(cl & "_份数"))
End If
End If
Next
Next