找回密码
 加入
搜索
查看: 2230|回复: 9

有高手会写这个读取access数据的吗?

[复制链接]
发表于 2008-10-18 22:00:33 | 显示全部楼层 |阅读模式
有谁会写一个只要输入id_usernum就会自动读取数据库的id_key、id_name和id_idcard的。
数据库的密码是:rzx1218
数据库如下:

[ 本帖最后由 s77m72 于 2008-10-20 23:09 编辑 ]

本帖子中包含更多资源

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

×
 楼主| 发表于 2008-10-19 00:49:11 | 显示全部楼层
在人可以帮一下忙吗?
发表于 2008-10-19 10:20:34 | 显示全部楼层
帮助新人,

#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
 楼主| 发表于 2008-10-19 11:23:46 | 显示全部楼层
D:\Program Files\System\桌面\新建 AutoIt v3 脚本 (3).au3 (74) : ==> 请求动作失败(请求于对象).:
GUICtrlSetData($Input2,$RS.Fields(3).value)
GUICtrlSetData($Input2,$RS.Fields(3).value^ ERROR
这是怎么了..
 楼主| 发表于 2008-10-19 13:01:29 | 显示全部楼层
如果改成截图的样子应该怎么做啊?

本帖子中包含更多资源

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

×
 楼主| 发表于 2008-10-19 17:08:37 | 显示全部楼层
高手门会不会啊?帮忙解决一下吧
 楼主| 发表于 2008-10-19 21:18:40 | 显示全部楼层
可以帮帮忙看一下吗?在线等
发表于 2008-10-20 19:02:19 | 显示全部楼层
#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楼同志加了个判断
发表于 2009-4-11 01:07:45 | 显示全部楼层
我想请问一下如果要将数据读取到Combo的循环代码应该怎么写??
发表于 2009-9-3 00:36:01 | 显示全部楼层
看看有没有我要的
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-28 02:29 , Processed in 0.076040 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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