以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 请问为何插入1000行需要20秒,如何提高效率? (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=187924) |
-- 作者:hbhb -- 发布时间:2023/8/21 16:41:00 -- 请问为何插入1000行需要20秒,如何提高效率? 大师:窗口中的表 请问为何插入1000行需要20秒,如何提高效率?
|
-- 作者:有点蓝 -- 发布时间:2023/8/21 16:43:00 -- 屏蔽表事件,表达式列计算 |
-- 作者:hbhb -- 发布时间:2023/8/21 16:53:00 -- 已经用了下面的代码后还要20秒,否则更长。 SystemReady = False |
-- 作者:有点蓝 -- 发布时间:2023/8/21 16:56:00 -- 什么数据库?贴出完整代码看看 |
-- 作者:hbhb -- 发布时间:2023/8/21 17:07:00 -- Dim st As Date = Date.Now Dim tb29 As WinForm.Table = Forms("窗口1").Controls("Table1") Dim tb As Table = tb29.Table tb.Position = 5 窗口中的10列表 SystemReady = False Try For n As Integer = 1 To 1000 tb.InsertNew Next Catch ex As Exception MessageBox.Show("追加数据失败") End Try SystemReady = True MessageBox.Show("耗时: " & (Date.Now - st).TotalSeconds & "秒")
|
-- 作者:有点蓝 -- 发布时间:2023/8/21 17:25:00 -- 每插入1行要计算sortkey的值,当然慢了 换种方法,先添加1000行,再更改sorkey值 Dim st As Date = Date.Now Dim tb29 As WinForm.Table = Forms("窗口1").Controls("Table1") Dim tb As Table = tb29.Table tb.Position = 5 Dim a As Decimal = tb.rows(4)("_sortkey") Dim b As Decimal = tb.rows(5)("_sortkey") Dim c As Decimal = (b - a) / 1010 Dim max As Integer = tb.rows.Count - 1 tb.StopRedraw SystemReady = False tb.AddNew(1000) \'窗口中的10列表 Try For n As Decimal = 1 To 1000 a = a + c tb.rows(max + n)("_sortkey") = a Next Catch ex As Exception MessageBox.Show("追加数据失败") End Try SystemReady = True tb.ResumeRedraw MessageBox.Show("耗时: " & (Date.Now - st).TotalSeconds & "秒") |