shenrenba 发表于 2010-9-9 17:00:38

如何从SQLITE数据库中读取数据并显示在ComboBox中(已解决)

本帖最后由 shenrenba 于 2010-9-9 17:13 编辑

RT, 帮我修改下代码Msgbox显示的都对 就是控件中显示为空

-------------------------
用错函数了...


#include <SQLite.au3>
#include <SQLite.dll.au3>
#include <ButtonConstants.au3>
#include <GuiComboBoxEx.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$sqlpath = @ScriptDir & "\ceshi.db"
$sqlname = "ceshi"
_SQLite_Startup()
Local $hQuery, $aRow
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 623, 442, 192, 124)
$Group1 = GUICtrlCreateGroup("Group1", 96, 48, 385, 209)
$Combo1 = _GUICtrlComboBox_Create($Form1, "", 160, 104, 249, 25, $CBS_DROPDOWN + $CBS_AUTOHSCROLL + $CBS_SIMPLE)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
xs()
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

        EndSwitch
WEnd
Func xs()
        _SQLite_Open($sqlpath)
        _SQLite_Exec(-1, "CREATE TABLE " & $sqlname & " (a,b,c);")
        _SQLite_Exec(-1, "INSERT INTO " & $sqlname & " (a,b,c) VALUES ('c','2','World');")
        _SQLite_Exec(-1, "INSERT INTO " & $sqlname & " (a,b,c) VALUES ('b','3',' ');")
        _SQLite_Exec(-1, "INSERT INTO " & $sqlname & " (a,b,c) VALUES ('a','1','Hello');")
        _SQLite_Query(-1, "SELECT * FROM " & $sqlname & " ORDER BY a DESC;", $hQuery)
        While _SQLite_FetchData($hQuery, $aRow) = $SQLITE_OK
                MsgBox(0, "", $aRow)
                _GUICtrlComboBoxEx_BeginUpdate($Combo1)
                _GUICtrlComboBox_AddString($Combo1, $aRow)
                _GUICtrlComboBoxEx_EndUpdate($Combo1)
        WEnd
        _SQLite_Close()
EndFunc   ;==>xs

3mile 发表于 2010-9-9 17:43:25

回复 1# shenrenba
第16行增加_GUICtrlComboBoxEx_InitStorage ($Combo1, 1000, 5000)试试。

shenrenba 发表于 2010-9-10 08:36:03

回复 2# 3mile


    你的方法不可行的是函数错误


40行 _GUICtrlComboBox_AddString 不能用_GUICtrlComboBoxEX_AddString

udbghdto 发表于 2011-8-5 11:12:52

怎么做的,我也想知道

cks1203 发表于 2011-9-2 16:48:10

此方髮學習中

805333 发表于 2012-2-14 03:44:17

急需这方面资料

netegg 发表于 2012-2-14 07:09:02

本帖最后由 netegg 于 2012-2-14 07:31 编辑

#include <SQLite.au3>
#include <SQLite.dll.au3>
#include <ButtonConstants.au3>
#include <GuiComboBoxEx.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$sqlpath = @ScriptDir & "\ceshi.db"
$sqlname = "ceshi"
_SQLite_Startup()
Local $hQuery, $aRow
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 623, 442, 192, 124)
$Group1 = GUICtrlCreateGroup("Group1", 96, 48, 385, 209)
$Combo1 = _GUICtrlComboBox_Create($Form1, "", 160, 104, 249, 25, $CBS_DROPDOWN + $CBS_AUTOHSCROLL + $CBS_SIMPLE)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
xs()
#endregion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

        EndSwitch
WEnd
Func xs()
        _SQLite_Open($sqlpath)
        _SQLite_Exec(-1, "CREATE TABLE " & $sqlname & " (a,b,c);")
        _SQLite_Exec(-1, "INSERT INTO " & $sqlname & " (a,b,c) VALUES ('c','2','World');")
        _SQLite_Exec(-1, "INSERT INTO " & $sqlname & " (a,b,c) VALUES ('b','3',' ');")
        _SQLite_Exec(-1, "INSERT INTO " & $sqlname & " (a,b,c) VALUES ('a','1','Hello');")
        _SQLite_Query(-1, "SELECT * FROM " & $sqlname & " ORDER BY a DESC;", $hQuery)
        ;                _GUICtrlComboBoxEx_InitStorage($Combo1, 150, 300)
        _GUICtrlComboBoxEx_BeginUpdate($Combo1)
        While _SQLite_FetchData($hQuery, $aRow) = $SQLITE_OK
                ;                MsgBox(0, "", $aRow)
                _GUICtrlComboBox_AddString($Combo1, $aRow)
                ;                                ExitLoop
        WEnd
        _GUICtrlComboBoxEx_EndUpdate($Combo1)
        _SQLite_Close()
EndFunc   ;==>xs

netegg 发表于 2012-2-14 07:30:31

本帖最后由 netegg 于 2012-2-14 07:36 编辑

回复 2# 3mile

小数据量似乎不用对存储空间先进行初始化

netegg 发表于 2012-2-14 07:38:01

本帖最后由 netegg 于 2012-2-14 07:53 编辑

回复 3# shenrenba

函数是没错的,ex本身就可以操作非ex的combo控件,只是可选参数多了不少
另外再说一句,编程别太死,combo(ex)不但能操作自己建立的,外部控件都行
页: [1]
查看完整版本: 如何从SQLITE数据库中读取数据并显示在ComboBox中(已解决)