Rss & SiteMap

Foxtable(狐表) http://www.foxtable.com

新一代数据库软件,完美融合Access、Foxpro、Excel、vb.net之优势,人人都能掌握的快速软件开发工具!
共11 条记录, 每页显示 10 条, 页签: [1] [2]
[浏览完整版]

标题:[求助]填充数据时遇到困难

1楼
xl 发表于:2010/4/22 20:00:00
 

下列代码可将“教师安排”列填充到“任课教师分析表”的“科目”和“教师”两列,请问如何修改下列代码,可将“班级”列一并填充?

Dim s As Date = Date.Now()

DataTables("任课教师分析").DataRows.Clear()

Dim Values() As String

Dim n As Integer = Tables("教师安排").rows.count

Dim n1 As Integer

for Each dc as Datacol in DataTables("教师安排").Datacols

    if dc.name <> "班级" Then

        n1 = n1 +1

        dim f As New Filler

        f.SourceTable = DataTables("教师安排") '指定数据来源

        f.SourceCols = dc.name '指定数据来源列

        f.DataTable = DataTables("任课教师分析") '指定数据接收表

        f.DataCols = "教师" '指定数据接收列

        f.Distinct = false

        f.Fill() '填充数据

        For i As integer = (n*n1)-n to Tables("任课教师分析").rows.count -1

           Tables("任课教师分析").Rows(i)("科目") = dc.name

           Tables("任课教师分析").Rows(i)("班级") = ?????

        Next

    end if

Next

Messagebox.Show("处理完毕! 耗时: " & (Date.Now -s).TotalSeconds)

原设计有两点不满意:一是速度太慢;二是填充后删除空值。原代码:
'填充"科目-班级-教师"3列数据
Dim s As Date = Date.Now()
DataTables("任课教师分析").DataRows.Clear
For j As Integer = 0 To 6
    For i As Integer = 0 To 17
        Dim r As Row = Tables("任课教师分析").AddNew
        r("科目") = Tables("教师安排").Cols(j + 1).Name
        r("班级") = i + 1
        r("教师") = Tables("教师安排")(i,j + 1)
    Next
Next
DataTables("任课教师分析").DeleteFor("[教师]  Is Null")

[此贴子已经被作者于2010-4-22 20:03:14编辑过]
2楼
xl 发表于:2010/4/22 20:02:00

相关表格:1、教师安排


2、任课教师分析

[此贴子已经被作者于2010-4-22 21:59:27编辑过]
3楼
mr725 发表于:2010/4/22 20:47:00
直接这样可以了吧:
       dim f As New Filler

        f.SourceTable = DataTables("教师安排")     '指定数据来源

        f.SourceCols = "班级," & dc.name             '指定数据来源列

        f.DataTable = DataTables("任课教师分析")   '指定数据接收表

        f.DataCols = "班级,教师" '指定数据接收列

        f.Distinct = false

        f.Fill() '填充数据

[此贴子已经被作者于2010-4-22 23:36:58编辑过]
4楼
xl 发表于:2010/4/22 21:07:00

出现错误提示

5楼
xl 发表于:2010/4/22 21:28:00

 

[此贴子已经被作者于2010-4-22 22:14:44编辑过]
6楼
czy 发表于:2010/4/22 21:31:00
改成这样试试

"""班级," & dc.Name & """"
7楼
xl 发表于:2010/4/22 21:41:00
出错提示如下:

图片点击可在新窗口打开查看此主题相关图片如下:335.bmp
图片点击可在新窗口打开查看
8楼
lxl 发表于:2010/4/22 21:57:00

Dim s As Date = Date.Now()

DataTables("任课教师分析").DataRows.Clear()

Dim Values() As String

Dim n As Integer = Tables("教师安排").rows.count

Dim n1 As Integer

for Each dc as Datacol in DataTables("教师安排").Datacols

    if dc.name <> "班级" Then

        n1 = n1 +1

        dim f As New Filler

        f.SourceTable = DataTables("教师安排") '指定数据来源

        f.SourceCols = dc.name & ",班级" '指定数据来源列

        f.DataTable = DataTables("任课教师分析") '指定数据接收表

        f.DataCols = "教师,班级" '指定数据接收列

        f.Distinct = false

        f.Fill() '填充数据

        For i As integer = (n*n1)-n to Tables("任课教师分析").rows.count -1

           Tables("任课教师分析").Rows(i)("科目") = dc.name

        Next

    end if

Next

Messagebox.Show("处理完毕! 耗时: " & (Date.Now -s).TotalSeconds)

9楼
xl 发表于:2010/4/22 21:59:00
谢谢!
10楼
mr725 发表于:2010/4/22 23:34:00
你原来代码稍加改进也是可以很快的呀, 至于空值,都要另外删除吧

Dim s As Date = Date.Now()
DataTables("任课教师分析").DataRows.Clear
Dim n As Integer = Tables("教师安排").rows.count
Dim n1 As Integer = Tables("教师安排").cols.count-1
Tables("任课教师分析").AddNew(n*n1)
For j As Integer = 0 To 6
    For i As Integer = 0 To 17
        Tables("任课教师分析")(i+j*18,"科目") = Tables("教师安排").Cols(j+1).Name
        Tables("任课教师分析")(i+j*18,"班级") = i + 1
        Tables("任课教师分析")(i+j*18,"教师") = Tables("教师安排")(i,j+1)
    Next
Next
DataTables("任课教师分析").DeleteFor("[教师]  Is Null")
Messagebox.Show("处理完毕! 耗时: " & (Date.Now -s).TotalSeconds)   ‘我这里 0.1 秒

------------------------------------------
或者:
  加两行代码: 也是飞快的呀:::::
-----------------------------------------
Dim s As Date = Date.Now()
Tables("任课教师分析").Redraw = False   
DataTables("任课教师分析").DataRows.Clear
For j As Integer = 0 To 6
    For i As Integer = 0 To 17
        Dim r As Row = Tables("任课教师分析").AddNew
        r("科目") = Tables("教师安排").Cols(j + 1).Name
        r("班级") = i + 1
        r("教师") = Tables("教师安排")(i,j + 1)
    Next
Next
DataTables("任课教师分析").DeleteFor("[教师]  Is Null")
Tables("任课教师分析").Redraw = true   
Messagebox.Show("处理完毕! 耗时: " & (Date.Now -s).TotalSeconds)

[此贴子已经被作者于2010-4-23 0:06:44编辑过]
共11 条记录, 每页显示 10 条, 页签: [1] [2]

Copyright © 2000 - 2018 foxtable.com Tel: 4000-810-820 粤ICP备11091905号

Powered By Dvbbs Version 8.3.0
Processed in .03320 s, 2 queries.