以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 关于导入后保存的效率问题 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=89549) |
-- 作者:zhy400137 -- 发布时间:2016/8/24 11:02:00 -- 关于导入后保存的效率问题 1070行数据高速合并进系统后,用FOXTABLE保存非常慢,搜索论坛后,发现了以下办法 http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=52855&authorid=0&page=0&star=1 但我照写代码后,保存依然很慢,1070行数据要116秒,不清楚是什么原因,请老师指正。 其中因我的ID是自增列,所以在原代码基础上加了个IF判断,如果列名为ID,就不合并进SQL语句。 Dim dt As Date = Date.Now Dim cmd As New SQLCommand cmd.C Dim sql1,sql2 As String For Each c As Col In Tables("上年实际数导入").Cols If c.Name<>"ID" Then sql1 + = c.Name & "," End If Next For Each r As Row In Tables("上年实际数导入").Rows sql2 = "" For Each c As Col In Tables("上年实际数导入").Cols If c.Name<>"ID" Then If c.IsDate Then sql2 + = "\'" & r(c.Name) & "\'" & "," ElseIf c.IsString Then sql2 + = "\'" & r(c.Name) & "\'," ElseIf c.IsBoolean Then If r(c.Name) = True Then sql2 + = 1 & "," ElseIf r(c.Name) = False Then sql2 + = 0 & "," End If Else sql2 + = r(c.Name) & "," End If End If Next cmd.CommandText + = "S elect " & sql2.Trim(",") & vbcrlf & "Union All" & vbcrlf Next cmd.CommandText = "I nSert Into 上年实际数导入 (" & sql1.Trim(",") & ")" & vbcrlf & cmd.CommandText.SubString(0,cmd.CommandText.Length - 11) cmd.ExecuteNonQuery DataTables("上年实际数导入").Load Dim tp As TimeSpan tp = Date.Now - dt MessageBox.Show(tp.TotalSeconds) |
-- 作者:Hyphen -- 发布时间:2016/8/24 11:16:00 -- 这样都慢,就要考虑是不是网络慢,或者数据库需要优化了。 把生成的sql拿到数据库执行,慢不慢?加载数据慢不慢?
|
-- 作者:zhy400137 -- 发布时间:2016/8/24 11:25:00 -- 谢谢楼上两位,2楼高手。 |