本帖最后由 kk_lee69 于 2012-8-20 13:39 编辑
因为工作上的需要 经常要与 数据库沟通….所以做了个小测试 把心得整理出来…….
传统方法是 一笔一笔的汇数据 如下所示….但是数据量一大的时候 就会变很慢……10万笔数据 实际测试大约 需要500秒
Dim $Server = "DBSERVERSQL"
Dim $Company = "Z100A01001"
DIM $array[1][1]
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <array.au3>
#include <Date.au3>
#include <GuiConstants.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#RequireAdmin
$WinMain = GuiCreate('TEST',800,600)
$menu2 = GuiCtrlCreateButton('RUN', 210, 30, 150, 30);
GUICtrlSetFont(-1,10)
$ListView1 = GUICtrlCreateListView("a |b |c |d |e |f |g ", 32, 100, 705, 401)
$conn = ObjCreate("ADODB.Connection")
$RS = ObjCreate("ADODB.Recordset")
$conn.Open ("driver={SQL Server};server="&$Server&";uid=sa;pwd=123;database="&$Company);
$RS.ActiveConnection = $conn;
GuiSetState()
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
Case $menu2
$iTimer = TimerInit()
$RS.open ("SELECT LA001,LA004,LA006,LA007,LA008,LA009,LA010 FROM INVLA Where LA010 like 'AMB%'");
While (Not $RS.eof And Not $RS.bof);
GUICtrlCreateListViewItem($RS.Fields(0).value&"|"&$RS.Fields(1).value&"|"&$RS.Fields(2).value&"|"&$RS.Fields(3).value&"|"&$RS.Fields(4).value&"|"&$RS.Fields(5).value&"|"&$RS.Fields(6).value, $ListView1 )
$RS.movenext;
WEnd;
$RS.close;
MsgBox(4160, "Information", "Load time: " & TimerDiff($iTimer) / 1000 & " seconds")
EndSwitch
WEnd
如果改成先将 取得的数据 放入到数组里面…. 在一次汇入 LISTVIEW 这样就大约 只需要15秒 如果数据是55万笔 也只要 85秒左右 如下所示:
Dim $Server = "DBSERVERSQL"
Dim $Company = "Z100A01001"
DIM $array[1][1]
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <array.au3>
#include <Date.au3>
#include <GuiConstants.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#RequireAdmin
$WinMain = GuiCreate('TEST',800,600)
$menu2 = GuiCtrlCreateButton('RUN', 210, 30, 150, 30);
GUICtrlSetFont(-1,10)
$ListView1 = GUICtrlCreateListView("a |b |c |d |e |f |g ", 32, 100, 705, 401)
$conn = ObjCreate("ADODB.Connection")
$RS = ObjCreate("ADODB.Recordset")
$conn.Open ("driver={SQL Server};server="&$Server&";uid=sa;pwd=123;database="&$Company);
$RS.ActiveConnection = $conn;
GuiSetState()
; 顯示視窗
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
Case $menu2
$RS.open ("SELECT COUNT(*) FROM INVLA Where LA010 like 'AMB%'");
While (Not $RS.eof And Not $RS.bof);
$P=$RS.Fields(0).value
$RS.movenext;
WEnd;
$RS.close;
Dim $APP[$P][7]
$i=0
$iTimer = TimerInit()
$RS.open ("SELECT LA001,LA004,LA006,LA007,LA008,LA009,LA010 FROM INVLA Where LA010 like 'AMB%'");
While (Not $RS.eof And Not $RS.bof);
$APP[$i][0]=$RS.Fields(0).value
$APP[$i][1]=$RS.Fields(1).value
$APP[$i][2]=$RS.Fields(2).value
$APP[$i][3]=$RS.Fields(3).value
$APP[$i][4]=$RS.Fields(4).value
$APP[$i][5]=$RS.Fields(5).value
$APP[$i][6]=$RS.Fields(6).value
$i=$i+1
;GUICtrlSetState($SETDATA,$GUI_ENABLE)
$RS.movenext;
WEnd;
$RS.close;
_GUICtrlListView_AddArray($ListView1, $APP)
MsgBox(4160, "Information", "Load time: " & TimerDiff($iTimer) / 1000 & " seconds")
EndSwitch
WEnd
这是 目前 发现最好的写法了 欢迎 有更好写法的朋友 提出来讨论 |