本帖最后由 南一 于 2012-7-6 21:01 编辑
前段时间刚好在搞数据库的效率读取和显示,试验了很多种方法,下面这种的效率算是还蛮优的。
读取一个20个字段,2000条数据的Access表格,读数据库花费1S左右,显示到Listview用了0.4S左右。
下面提供的这个数据库是网上随便找的,可以测试下,我这边测试【连接数据库,读取表,显示到listview】共花费0.6S。
用SQlLite的话,数据库连接部分代码换一下就行了。
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#region ### START Koda GUI section ### Form=
Dim $DataCount = 0
Local $iExListViewStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER)
$Form1 = GUICreate("Test3", 603, 470, 192, 124, BitOR($WS_MINIMIZEBOX, $WS_MAXIMIZEBOX, $WS_SIZEBOX))
$LVData = GUICtrlCreateListView("A|B|C|D|E|F|G|H|I|J|K|L|M ", 8, 10, 585, 380)
_GUICtrlListView_SetExtendedListViewStyle($LVData, $iExListViewStyle)
GUICtrlSetResizing(-1, $GUI_DOCKBORDERS + $GUI_DOCKTOP)
$BtnRefresh = GUICtrlCreateButton("刷新", 8, 400, 586, 33)
GUICtrlSetResizing(-1, $GUI_DOCKBOTTOM + $GUI_DOCKLEFT)
GUISetState(@SW_SHOW)
GUISetState(@SW_MAXIMIZE, $Form1)
#endregion ### END Koda GUI section ###
$Begin = TimerInit()
read()
$End = TimerDiff($Begin)
MsgBox(64, "读取", "共" & $DataCount & "条数据,共花费" & $End)
WinActivate($Form1)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func Read()
_GUICtrlListView_BeginUpdate($LVData)
$MDBDataPath = @ScriptDir & "\Northwind.mdb"
$Read = ObjCreate("ADODB.Connection")
$Read.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $MDBDataPath)
$UD_ = ObjCreate("ADODB.Recordset")
$UD_.ActiveConnection = $Read
$UD_.Open("Select * From QueryOrders")
While Not $UD_.eof And Not $UD_.bof
GUICtrlCreateListViewItem($UD_.Fields(0).value & "|" & $UD_.Fields(1).value & "|" & $UD_.Fields(2).value & "|" & $UD_.Fields(3).value & "|" & $UD_.Fields(4).value & "|" & $UD_.Fields(5).value & "|" & $UD_.Fields(6).value & "|" & $UD_.Fields(7).value & "|" & $UD_.Fields(8).value & "|" & $UD_.Fields(9).value & "|" & $UD_.Fields(10).value & "|" & $UD_.Fields(11).value & "|" & $UD_.Fields(12).value, $LVData)
$DataCount += 1
$UD_.movenext
WEnd
$UD_.close
$Read.close
_GUICtrlListView_EndUpdate($LVData)
EndFunc ;==>Read
|