找回密码
 加入
搜索
查看: 3447|回复: 10

[系统综合] 如何用下拉列表显示数据库里的内容?[已解决]

  [复制链接]
发表于 2011-3-5 12:38:12 | 显示全部楼层 |阅读模式
本帖最后由 fanchenglu 于 2011-3-11 00:52 编辑

如题  如何在下拉列表中显示 sql数据库 内容 以供选择?

就是一张表里面 有部门名称信息和部门id   查询出部门名字后想让它在下拉列表中出现以供选择  然后后面更具选择到的部门到另一张表中条件查询
请高手做个例子
没有人可以解决么?

之前附件是win7默认压缩,系统带了密码,现在改了。
真抱歉,win7压缩 自动加密,程序所有的都完成了 就差如何把部门显示在下拉列表了

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2011-3-5 15:42:24 | 显示全部楼层
数据库拿来 我有兴趣做做看。
发表于 2011-3-5 15:46:43 | 显示全部楼层
将查询结果放入结果即可
发表于 2011-3-5 16:56:07 | 显示全部楼层
把内容SET进去就行,内容要先取得
 楼主| 发表于 2011-3-5 21:20:58 | 显示全部楼层
回复 2# nmgwddj
高手请帮帮忙
库我已经放到上面了  谢谢
发表于 2011-3-8 18:45:08 | 显示全部楼层
回复 5# fanchenglu


    压缩包是加密的………………
 楼主| 发表于 2011-3-9 07:48:18 | 显示全部楼层
真抱歉,win7压缩 自动加密,程序所有的都完成了 就差如何把部门显示在下拉列表了
 楼主| 发表于 2011-3-10 00:52:09 | 显示全部楼层
回复 6# nmgwddj


   已经改了 没有密码了 谢谢
发表于 2011-3-10 04:22:00 | 显示全部楼层
本帖最后由 kodin 于 2011-3-10 04:26 编辑

刚看到,顺手帮你做了个例子,还好是MYSQL。
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)

$Form1 = GUICreate("Form1", 360, 140, -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")

$Label1 = GUICtrlCreateLabel("服务器 IP", 8, 12, 55, 17)
$Label2 = GUICtrlCreateLabel("数据库 ID", 8, 44, 55, 17)
$Label3 = GUICtrlCreateLabel("数据库 PW", 8, 76, 55, 17)
$Label4 = GUICtrlCreateLabel("数据库 DA", 8, 108, 55, 17)

$Input1 = GUICtrlCreateInput("", 65, 8, 121, 21)
$Input2 = GUICtrlCreateInput("", 65, 40, 121, 21)
$Input3 = GUICtrlCreateInput("", 65, 72, 121, 21)
$Input4 = GUICtrlCreateInput("", 65, 104, 121, 21)

$Combo1 = GUICtrlCreateCombo("", 200, 8, 145, 25, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE))
GUICtrlSetState($Combo1, $GUI_DISABLE)
GUICtrlSetOnEvent($Combo1, "Combo1")

$Combo2 = GUICtrlCreateCombo("", 200, 40, 145, 25, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE))
GUICtrlSetState($Combo2, $GUI_DISABLE)
GUICtrlSetOnEvent($Combo2, "Combo2")

$Combo3 = GUICtrlCreateCombo("", 200, 72, 145, 25, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE))
GUICtrlSetState($Combo3, $GUI_DISABLE)

$Button1 = GUICtrlCreateButton("连接数据库", 200, 104, 145, 25)
GUICtrlSetOnEvent($Button1, "Button1")

GUISetState(@SW_SHOW)

While 1
        Sleep(100)
WEnd
Func Button1()
        $conn = ObjCreate("ADODB.Connection")
        $RS = ObjCreate("ADODB.Recordset")
        $conn.Open("driver={SQL Server};server=" & GUICtrlRead($Input1) & ";uid=" & GUICtrlRead($Input2) & ";pwd=" & GUICtrlRead($Input3) & ";database=" & GUICtrlRead($Input4) & "")
        $RS.ActiveConnection = $conn
        Dim $hardware = "idcy_dept,idcy_user_info"
        $RS.open("select * from " & $hardware & " where " & "idcy_dept.bmdm=idcy_user_info.bmdm")
        Local $n = 0
        While Not $RS.eof And Not $RS.bof
                GUICtrlSetData($Combo1, $RS.Fields(2).value)
                $n += 1
                $RS.movenext
        WEnd
        $RS.close
        GUICtrlSetState($Combo1, $GUI_ENABLE)
EndFunc   ;==>Button1


Func Combo1()
        $conn = ObjCreate("ADODB.Connection")
        $RS = ObjCreate("ADODB.Recordset")
        $conn.Open("driver={SQL Server};server=" & GUICtrlRead($Input1) & ";uid=" & GUICtrlRead($Input2) & ";pwd=" & GUICtrlRead($Input3) & ";database=" & GUICtrlRead($Input4) & "")
        $RS.ActiveConnection = $conn
        Dim $hardware = "idcy_dept,idcy_user_info"
        $RS.open("select * from " & $hardware & " where " & "(idcy_dept.bmdm=idcy_user_info.bmdm) and (idcy_dept.name=" & "'" & GUICtrlRead($Combo1) & "'" & ")")
        Local $n = 0
        While Not $RS.eof And Not $RS.bof
                GUICtrlSetData($Combo2, $RS.Fields(7).value)
                $n += 1
                $RS.movenext
        WEnd
        $RS.close
        GUICtrlSetState($Combo2, $GUI_ENABLE)
EndFunc   ;==>Combo1

Func Combo2()
        $conn = ObjCreate("ADODB.Connection")
        $RS = ObjCreate("ADODB.Recordset")
        $conn.Open("driver={SQL Server};server=" & GUICtrlRead($Input1) & ";uid=" & GUICtrlRead($Input2) & ";pwd=" & GUICtrlRead($Input3) & ";database=" & GUICtrlRead($Input4) & "")
        $RS.ActiveConnection = $conn
        Dim $hardware = "idcy_dept,idcy_user_info"
        $RS.open("select * from " & $hardware & " where (idcy_dept.bmdm=idcy_user_info.bmdm) and (idcy_dept.name=" & "'" & GUICtrlRead($Combo1) & "') and (idcy_user_info.user_sex=" & "'" & GUICtrlRead($Combo2) & "')")
                
        Local $n = 0
        While Not $RS.eof And Not $RS.bof
                GUICtrlSetData($Combo3, $RS.Fields(5).value)
                $n += 1
                $RS.movenext
        WEnd
        $RS.close
        GUICtrlSetState($Combo3, $GUI_ENABLE)
EndFunc   ;==>Combo2

Func Close()
        Exit
EndFunc   ;==>Close
我今天怎么这么蛋疼啊......
 楼主| 发表于 2011-3-11 00:48:47 | 显示全部楼层
非常感谢kodin
问题解决 完全依据你提供的代码
thank you
发表于 2013-8-1 07:28:03 | 显示全部楼层
标记一下,以后用得上
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-28 23:36 , Processed in 0.085332 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表