有高手会写这个读取access数据的吗?
有谁会写一个只要输入id_usernum就会自动读取数据库的id_key、id_name和id_idcard的。数据库的密码是:rzx1218
数据库如下:
[ 本帖最后由 s77m72 于 2008-10-20 23:09 编辑 ] 在人可以帮一下忙吗? 帮助新人,
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 633, 453, 190, 120)
$ListView1 = GUICtrlCreateListView("|||||||||||||||", 8, 200, 618, 246)
GUICtrlSendMsg($ListView1, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
$Input1 = GUICtrlCreateInput("", 100, 16, 121, 21)
$Input2 = GUICtrlCreateInput("", 100, 56, 121, 21)
$Input3 = GUICtrlCreateInput("", 100 ,96, 121, 21)
$Input4 = GUICtrlCreateInput("", 100, 136, 121, 21)
$Label1 = GUICtrlCreateLabel("id_usernum",16, 16, 80, 17)
$Label2 = GUICtrlCreateLabel("id_key", 16, 56, 80, 17)
$Label3 = GUICtrlCreateLabel("id_name", 16, 96, 80, 17)
$Label4 = GUICtrlCreateLabel("id_idcard", 16, 136, 80, 17)
$Button1 = GUICtrlCreateButton("read", 400, 80, 75, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
list()
EndSwitch
WEnd
Func list()
Local $listvalue,$id_usernum
$id_usernum=GUICtrlRead($Input1)
$Conn = ObjCreate("ADODB.Connection")
$Conn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=RZXCard.mdb;Jet OLEDB:Database Password='rzx1218'")
$RS = ObjCreate("ADODB.Recordset")
$sentence="select * from registerhistory where id_usernum='"&$id_usernum&"'"
$RS.ActiveConnection = $Conn
$RS.Open($sentence)
GUICtrlSetData($Input2,$RS.Fields(3).value)
GUICtrlSetData($Input3,$RS.Fields(2).value)
GUICtrlSetData($Input4,$RS.Fields(6).value)
_GUICtrlListView_DeleteAllItems($ListView1)
For $i = 0 To ($RS.Fields.Count - 1)
_GUICtrlListView_SetColumn($ListView1, $i, $RS.Fields($i).Name)
Next
While (Not $RS.eof And Not $RS.bof)
For $i = 0 To ($RS.Fields.Count - 1)
$listvalue = $listvalue & $RS.Fields($i).value & "|" ;取得一行记录
Next
GUICtrlCreateListViewItem($listvalue, $ListView1);显示$listvalue
$RS.movenext ;移到下一条记录
$listvalue = "" ;清空
WEnd
$RS.close
$Conn.Close
EndFunc
D:\Program Files\System\桌面\新建 AutoIt v3 脚本 (3).au3 (74) : ==> 请求动作失败(请求于对象).:
GUICtrlSetData($Input2,$RS.Fields(3).value)
GUICtrlSetData($Input2,$RS.Fields(3).value^ ERROR
这是怎么了.. 如果改成截图的样子应该怎么做啊? 高手门会不会啊?帮忙解决一下吧 可以帮帮忙看一下吗?在线等 #include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 633, 453, 190, 120)
$ListView1 = GUICtrlCreateListView("|||||||||||||||", 8, 200, 618, 246)
GUICtrlSendMsg($ListView1, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
$Input1 = GUICtrlCreateInput("", 100, 16, 121, 21)
$Input2 = GUICtrlCreateInput("", 100, 56, 121, 21)
$Input3 = GUICtrlCreateInput("", 100, 96, 121, 21)
$Input4 = GUICtrlCreateInput("", 100, 136, 121, 21)
$Label1 = GUICtrlCreateLabel("id_usernum", 16, 16, 80, 17)
$Label2 = GUICtrlCreateLabel("id_key", 16, 56, 80, 17)
$Label3 = GUICtrlCreateLabel("id_name", 16, 96, 80, 17)
$Label4 = GUICtrlCreateLabel("id_idcard", 16, 136, 80, 17)
$Button1 = GUICtrlCreateButton("read", 400, 80, 75, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
list()
EndSwitch
WEnd
Func list()
Local $listvalue, $id_usernum
$id_usernum = GUICtrlRead($Input1)
$Conn = ObjCreate("ADODB.Connection")
$Conn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=RZXCard.mdb;Jet OLEDB:Database Password='rzx1218'")
$RS = ObjCreate("ADODB.Recordset")
$sentence = "select * from registerhistory where id_usernum='" & $id_usernum & "'"
$RS.ActiveConnection = $Conn
$RS.Open($sentence)
If$RS.eof Then
MsgBox(0, 0, "没有找到记录")
Else
GUICtrlSetData($Input2, $RS.Fields(3).value)
GUICtrlSetData($Input3, $RS.Fields(2).value)
GUICtrlSetData($Input4, $RS.Fields(6).value)
_GUICtrlListView_DeleteAllItems($ListView1)
For $i = 0 To ($RS.Fields.Count - 1)
_GUICtrlListView_SetColumn($ListView1, $i, $RS.Fields($i).Name)
Next
While (Not $RS.eof And Not $RS.bof)
For $i = 0 To ($RS.Fields.Count - 1)
$listvalue = $listvalue & $RS.Fields($i).value & "|" ;取得一行记录
Next
GUICtrlCreateListViewItem($listvalue, $ListView1);显示$listvalue
$RS.movenext ;移到下一条记录
$listvalue = "" ;清空
WEnd
$RS.close
$Conn.Close
EndIf
EndFunc ;==>list
你输入了不存在的记录所以出错了 帮3楼同志加了个判断 我想请问一下如果要将数据读取到Combo的循环代码应该怎么写?? 看看有没有我要的
页:
[1]