Foxtable(狐表)用户栏目专家坐堂 → [求助] 优化代码


  共有3325人关注过本帖树形打印复制链接

主题:[求助] 优化代码

帅哥哟,离线,有人找我吗?
wangyinming
  11楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:童狐 帖子:286 积分:2345 威望:0 精华:0 注册:2013/8/30 3:37:00
  发帖心情 Post By:2015/4/2 12:17:00 [只看该作者]

谢谢!合并数据2000条,还是有点慢。比之前快多了。

我这样写的,看看有没有问题?

Dim pr As Integer = DataTables("加硫").DataRows.Count     '查询表行数
Dim dlg As New OpenFileDialog '定义一个新的OpenFileDialog
dlg.Filter= "excel文件|*.xls" '设置筛选器
dlg.MultiSelect = True   '允许选择多个文件
If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮
    Dim mg As New Merger
    For Each fl As String In dlg.FileNames
        mg.SourcePath = fl '指定数据文件
        mg.Format = "excel" '指定格式
        mg.SourceTableName = "data$" '指定要合并的表
        mg.DataTableName = "加硫" '指定接收数据的表
        mg.Merge() '开始合并
    Next


Dim str As String = "管理号码,管理号码1,工号,生产数"
Dim idx As String = ""
Dim ary() As String = str.Split(",")
Dim pdr As DataRow = Nothing
Dim count As Integer = 0
For Each dr As DataRow In DataTables("加硫").Select("管理号码 is not null", str)
    Dim flag As Boolean = False
    For Each a As String In ary
        If pdr IsNot Nothing AndAlso dr(a) <> pdr(a) Then
            flag = True
        End If
    Next
    If flag = False Then
        count += 1
    Else
        'If count = 1 Then
            idx &= pdr("_Identify") & ","
        'End If
        count = 1
    End If
    pdr = dr
Next
For Each a As String In ary
    If pdr IsNot Nothing AndAlso Tables("加硫").Rows(Tables("加硫").Rows.count-2)(a) <> pdr(a) Then
        idx &= pdr("_Identify") & ","
    End If
Next

DataTables("加硫").DeleteFor("_Identify not in (" & idx.trim(",") & ")")  '去重复值

'DataTables("加硫").DeleteFor("[管理号码] is null or [良品] is null")  '删除空白行

pr = DataTables("加硫").DataRows.Count - pr '查询表行数


MessageBox.Show("成功导入数据"& pr &"条","提示")

Syscmd.Table.ToggleSortAndFilter()
DataTables("加硫").Save()
End If

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  12楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2015/4/2 14:10:00 [只看该作者]

 没办法,用代码只能是这样弄。代码应该没错。

 回到顶部
总数 12 上一页 1 2