回复 7# heroxianf
SQLIT3数据库方式
#NoTrayIcon
#AutoIt3Wrapper_UseX64 = no
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <MsgBoxConstants.au3>
#include <SQLite.au3>
#include <SQLite.dll.au3>
_SQLite_Startup()
If @error Then
MsgBox($MB_SYSTEMMODAL, "SQLite 错误", "SQLite3.dll 不能加载!")
Exit -1
EndIf
Local $sDbName = _TempFile()
Local $hDskDb = _SQLite_Open($sDbName) ; 打开一个永久的磁盘数据库
If @error Then
MsgBox($MB_SYSTEMMODAL, "SQLite 错误", "无法打开或创建一个永久性的数据库!")
Exit -1
EndIf
_SQLite_Exec(-1, "CREATE TABLE aTest (name ,max INT(8));") ; 创建一个表 注意,MAX表要为 整数类型 。不然_SetCB() 中的排序就没办法排列的了。
_SQLite_Exec(-1, "INSERT INTO aTest(name,max) VALUES ('李纯一','1');") ; 插入数据
_SQLite_Exec(-1, "INSERT INTO aTest(name,max) VALUES ('张有才','1');") ; 插入数据
_SQLite_Exec(-1, "INSERT INTO aTest(name,max) VALUES ('钟无艳','1');") ; 插入数据
_SQLite_Exec(-1, "INSERT INTO aTest(name,max) VALUES ('吕不淳','1');") ; 插入数据
_SQLite_Exec(-1, "INSERT INTO aTest(name,max) VALUES ('唯一一','1');") ; 插入数据
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 407, 226, 192, 124)
$Combo1 = GUICtrlCreateCombo("", 40, 32, 273, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
_SetCB(0)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
_SQLite_Close($hDskDb) ; DB 是一个普通的文件, 以后可以重新打开
FileDelete($sDbName)
_SQLite_Shutdown()
Exit
Case $Combo1
Local $aResult, $iRows, $iColumns, $iRval
; 查询
$iRval = _SQLite_GetTable(-1, "SELECT * FROM aTest WHERE name = '" & GUICtrlRead($Combo1) & "' ;", $aResult, $iRows, $iColumns)
If $iRval = $SQLITE_OK Then
;~ _ArrayDisplay($aResult, "查询结果")
;~ MsgBox(0,0,$aResult[4])
_SQLite_Exec(-1, "UPDATE aTest SET max =" & $aResult[4] + 1 & " WHERE name = '" & GUICtrlRead($Combo1) & "' ;")
_SetCB()
WinSetTitle($Form1, "", GUICtrlRead($Combo1) & "=" & $aResult[4] + 1)
Else
MsgBox($MB_SYSTEMMODAL, "SQLite 错误: " & $iRval, _SQLite_ErrMsg())
EndIf
EndSwitch
WEnd
Func _SetCB($Y = 1)
Local $hQuery, $aRow, $sMsg, $i = 0
_SQLite_Query($hDskDb, "SELECT * FROM aTest ORDER BY max desc ;", $hQuery) ; 查询
ConsoleWrite(@CRLF)
While _SQLite_FetchData($hQuery, $aRow,False,False) = $SQLITE_OK
If $i = 0 Then $sMs = $aRow[0]
$sMsg &= $aRow[0] & "|"
ConsoleWrite($aRow[0] & "|" &$aRow[1] & @CRLF)
$i += 1
WEnd
$sMsg = StringTrimRight($sMsg, 1)
If $Y <> 0 Then $sMs = GUICtrlRead($Combo1)
GUICtrlSetData($Combo1, "")
GUICtrlSetData($Combo1, $sMsg, $sMs)
EndFunc ;==>_SetCB
|