找回密码
 加入
搜索
楼主: 清风飘飘

[原创] au3操作Access基础教程

[复制链接]
发表于 2011-12-19 11:18:59 | 显示全部楼层
谢谢谢谢发布这个东西
发表于 2011-12-19 11:18:59 | 显示全部楼层
谢谢谢谢发布这个东西
发表于 2011-12-19 11:19:00 | 显示全部楼层
谢谢谢谢发布这个东西
发表于 2011-12-19 11:19:00 | 显示全部楼层
谢谢谢谢发布这个东西
发表于 2011-12-19 11:19:01 | 显示全部楼层
谢谢谢谢发布这个东西
发表于 2011-12-24 00:35:14 | 显示全部楼层
支持你一下,希望有更好的作品问世!
发表于 2011-12-27 22:34:23 | 显示全部楼层
好东西啊!
发表于 2011-12-27 22:36:54 | 显示全部楼层
留个脚印,好好学习!
发表于 2011-12-28 21:19:01 | 显示全部楼层
谢谢分享!~
发表于 2012-1-2 09:26:49 | 显示全部楼层
果然是个好东西
发表于 2012-1-5 20:45:34 | 显示全部楼层
楼主的  数据库基础.au3
#NoTrayIcon
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIListView.au3>
#include <Access.au3>

$Form1 = GUICreate("Form1", 400, 381, 290, 255)
$Label1 = GUICtrlCreateLabel("用户名", 30, 8, 45, 17)
$Label2 = GUICtrlCreateLabel("密码", 30, 32, 40, 17)
$Input1 = GUICtrlCreateInput("", 82, 5, 121, 21)
$Input2 = GUICtrlCreateInput("", 82, 29, 121, 21)
$Button1 = GUICtrlCreateButton("创建", 12, 52, 75, 25)
$Button2 = GUICtrlCreateButton("添加", 92, 52, 75, 25)
$ListView1 = GUICtrlCreateListView("编号|姓名|密码", 5, 80, 210, 220,BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
GUICtrlSendMsg(-1, 0x101E, 0, 45)
GUICtrlSendMsg(-1, 0x101E, 1, 80)
GUICtrlSendMsg(-1, 0x101E, 2, 80)
$Button3 = GUICtrlCreateButton("查看记录", 5, 305, 75, 25)
$Button8 = GUICtrlCreateButton("删除记录", 95, 305, 75, 25)
$Label3 = GUICtrlCreateLabel("用户名", 220, 8, 45, 17)
$Label4 = GUICtrlCreateLabel("密码", 220, 32, 40, 17)
$Input3 = GUICtrlCreateInput("",270, 5, 121, 21)
$Input4 = GUICtrlCreateInput("",270, 29, 121, 21)
$Button4 = GUICtrlCreateButton("用户名查询", 212, 52, 75, 25)
$Button5 = GUICtrlCreateButton("密码查询", 292, 52, 75, 25)

$Label3 = GUICtrlCreateLabel("用户名", 220, 100, 45, 17)
$Label4 = GUICtrlCreateLabel("密码", 220, 132, 40, 17)
$Input3 = GUICtrlCreateInput("",270, 100, 121, 21)
$Input4 = GUICtrlCreateInput("",270, 129, 121, 21)
$Button6 = GUICtrlCreateButton("读取选中项", 222, 160, 75, 25)
$Button7 = GUICtrlCreateButton("保存修改", 302, 160, 75, 25)
GUISetState(@SW_SHOW)

$mdb_data_path = @ScriptDir & "\tets.mdb"  ;脚本所在目录下生成名为test。mdb的数据库
$adTable = "users"  ;表名称

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        If Not FileExists($mdb_data_path) Then
                                $newMdb = ObjCreate("ADOX.Catalog")
                                $newMdb.Create("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path)
                                $newmdb.ActiveConnection.Close
                                $addtbl = ObjCreate("ADODB.Connection")
                                $addTbl.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path)
                                $addTbl.Execute("CREATE TABLE " & $adTable)
                                $addtbl.Close
                                
                                $addfld = ObjCreate("ADODB.Connection")
                                $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path)
                                $addfld.Execute("ALTER TABLE " & $adTable & " ADD id identity(1, 1) primary key,name text(255) ,pass text(255)")
                                $addfld.Close
                                MsgBox(64,"提示","建立数据库成功",5)
                        Else
                                MsgBox(64,"提示","你已经建立了一个数据库了",5)
                        EndIf
                Case $Button2
                        If GUICtrlRead($Input1) <> '' And GUICtrlRead($Input2) <> '' Then
                                $ipt1 = GUICtrlRead($Input1)
                                $ipt2 = GUICtrlRead($Input2)
                                $addfld = ObjCreate("ADODB.Connection")
                                $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path)
                                $addfld.Execute("insert into "&$adTable&" (name,pass) values('"&$ipt1&"','"&$ipt2&"')")
                                $addfld.close
                                MsgBox(48,'提示','添加记录成功!')
                                GUICtrlSetData($Input1,'')
                                GUICtrlSetData($Input2,'')
                                GUICtrlSetState($Input1,$GUI_FOCUS)
                        Else
                                MsgBox(48,'提示','用户名和密码错误')
                                GUICtrlSetState($Input1,$GUI_FOCUS)
                        EndIf
                Case $Button3
                        read()
                Case $Button4
                        $ipt3 = GUICtrlRead($Input3)
                        GUICtrlSendMsg($ListView1, $LVM_DELETEALLITEMS, 0, 0)
                        $addfld = ObjCreate("ADODB.Connection")
                        $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path)
                        $RS =ObjCreate("ADODB.Recordset")
                        $RS.ActiveConnection =$addfld
                        $RS.Open ("Select * From "& $adTable & " WHERE name" & " ='"&$ipt3&"'")
                        while Not $RS.eof And Not $RS.bof
                                if @error =1 Then ExitLoop
                                GUICtrlCreateListViewItem ( $RS.Fields (0).value&"|"& $RS.Fields (1).value&"|"& $RS.Fields (2).value,$ListView1 )
                                $rs.movenext
                        WEnd
                        $rs.close
                        $addfld.Close
                Case $Button5
                        $ipt4 = GUICtrlRead($Input4)
                        GUICtrlSendMsg($ListView1, $LVM_DELETEALLITEMS, 0, 0)
                        $addfld = ObjCreate("ADODB.Connection")
                        $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path)
                        $RS =ObjCreate("ADODB.Recordset")
                        $RS.ActiveConnection =$addfld
                        $RS.Open ("Select * From "& $adTable & " WHERE pass" & " ='"&$ipt4&"'")
                        while Not $RS.eof And Not $RS.bof
                                if @error =1 Then ExitLoop
                                GUICtrlCreateListViewItem ( $RS.Fields (0).value&"|"& $RS.Fields (1).value&"|"& $RS.Fields (2).value,$ListView1 )
                                $rs.movenext
                        WEnd
                        $rs.close
                        $addfld.Close
                Case $Button6
                        $Strn=GUICtrlRead(GUICtrlRead($ListView1))
                        $Strnspin=StringSplit($Strn,"|")
                        If $Strnspin[1]='0' Then
                                MsgBox(48,'提示','请选择要更新的条目')
                        Else
                                dataup()
                        EndIf
                Case $Button7
                        back()
                Case $Button8
                        del()

        EndSwitch
WEnd


Func dataup()
        $Strn=GUICtrlRead(GUICtrlRead($ListView1))
        $Strnspin=StringSplit($Strn,"|")
        GUICtrlSetData($Input3,'')
        GUICtrlSetData($Input4,'')
        $addfld = ObjCreate("ADODB.Connection")
        $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path)
        $RS =ObjCreate("ADODB.Recordset")
        $RS.ActiveConnection = $addfld
        $RS.Open ("Select * From " & $adTable &  " WHERE id" & " = " & $Strnspin[1])
        GUICtrlSetData($Input3,$RS.Fields (1).value)
        GUICtrlSetData($Input4,$RS.Fields (2).value)
        $rs.movenext
        $rs.close
        $addfld.Close
EndFunc

Func back()
        If GUICtrlRead($Input3)<>'' And GUICtrlRead($Input4)<>'' Then
                $read1=GUICtrlRead($Input3)
                $read2=GUICtrlRead($Input4)
                $Strn=GUICtrlRead(GUICtrlRead($ListView1))
                $Strnspin=StringSplit($Strn,"|")
                $addfld = ObjCreate("ADODB.Connection")
                $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path)
                $addfld.execute("update " & $adTable & " set  name='"&$read1&"',pass='"&$read2&"' WHERE id" & " = " & $Strnspin[1])
                $addfld.close
                GUICtrlSetData($Input3,'')
                GUICtrlSetData($Input4,'')
                read()
        Else
                MsgBox(48,'出错啦','请检查输入是否完整')
        EndIf
EndFunc

Func read()
        GUICtrlSendMsg($ListView1, $LVM_DELETEALLITEMS, 0, 0)
        $addfld = ObjCreate("ADODB.Connection")
        $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path)
        $RS =ObjCreate("ADODB.Recordset")
        $RS.ActiveConnection = $addfld
        $RS.Open ("Select * From " & $adTable )
        while Not $RS.eof And Not $RS.bof
                if @error =1 Then ExitLoop
                GUICtrlCreateListViewItem ( $RS.Fields (0).value&"|"& $RS.Fields (1).value&"|"& $RS.Fields (2).value,$ListView1 )
                $rs.movenext
        WEnd
        $rs.close
        $addfld.Close
EndFunc

Func del()
        $Strn=GUICtrlRead(GUICtrlRead($ListView1))
        $Strnspin=StringSplit($Strn,"|")
        $addfld = ObjCreate("ADODB.Connection")
        $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path)
        $sQuery ="DELETE FROM " & $adTable & " IN '" & $mdb_data_path & "' WHERE id" & " = " & $Strnspin[1]
        $addfld.execute($sQuery)
        $addfld.close
        read()
EndFunc

        
发表于 2012-1-8 23:57:45 | 显示全部楼层
谢谢。这些对我们新人有帮助。
发表于 2012-1-10 03:03:41 | 显示全部楼层
怎么没钱了?
发表于 2012-1-15 17:00:09 | 显示全部楼层
终于再次找到  可惜没分了
发表于 2012-1-21 20:38:58 | 显示全部楼层
不错。。。。学习了。。。。。。。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-3-28 18:36 , Processed in 0.072531 second(s), 15 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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