如何用下拉列表显示数据库里的内容?[已解决]
本帖最后由 fanchenglu 于 2011-3-11 00:52 编辑如题如何在下拉列表中显示 sql数据库 内容 以供选择?
就是一张表里面 有部门名称信息和部门id 查询出部门名字后想让它在下拉列表中出现以供选择然后后面更具选择到的部门到另一张表中条件查询
请高手做个例子
没有人可以解决么?
之前附件是win7默认压缩,系统带了密码,现在改了。
真抱歉,win7压缩 自动加密,程序所有的都完成了 就差如何把部门显示在下拉列表了 数据库拿来 我有兴趣做做看。 将查询结果放入结果即可 把内容SET进去就行,内容要先取得 回复 2# nmgwddj
高手请帮帮忙
库我已经放到上面了谢谢 回复 5# fanchenglu
压缩包是加密的……………… 真抱歉,win7压缩 自动加密,程序所有的都完成了 就差如何把部门显示在下拉列表了 回复 6# nmgwddj
已经改了 没有密码了 谢谢 本帖最后由 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{:face (394):}我今天怎么这么蛋疼啊...... 非常感谢kodin
问题解决 完全依据你提供的代码
thank you 标记一下,以后用得上
页:
[1]