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

[AU3基础] [已解决]连接access问题

  [复制链接]
发表于 2012-2-6 14:07:01 | 显示全部楼层 |阅读模式
本帖最后由 kimgmax 于 2012-2-9 13:00 编辑

$conn = ObjCreate("ADODB.Connection")               
                $conn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
                $conn.Execute('insert into note (Date,Type,Money,Remark) values("'& $Date&'","'&$Type&'","'&$Money&'","'&$Remark&'")')
报一下错误,
The requested action with this object has failed.:
$conn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
$conn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)^ ERROR

求助~~如何解决
发表于 2012-2-6 14:27:37 | 显示全部楼层
$mdb_data_path  你這個變數裡面的東西是甚麼
 楼主| 发表于 2012-2-6 14:28:34 | 显示全部楼层
Local $mdb_data_path = "mydb.mdb"
Local $mdb_data_pwd = "123456"
 楼主| 发表于 2012-2-6 14:29:54 | 显示全部楼层
我按网上查的例子写的,新手学习中~
发表于 2012-2-6 14:30:12 | 显示全部楼层
回复 3# kimgmax


    加上絕對路徑看看  .............
 楼主| 发表于 2012-2-6 14:31:57 | 显示全部楼层
加过绝对路径,结果也一样
发表于 2012-2-6 16:15:46 | 显示全部楼层
請先取消 資料庫的密碼  先測試 可以過 然後在解決密碼的問題
发表于 2012-2-7 01:50:35 | 显示全部楼层
回复 6# kimgmax
下面的代碼 絕對可用  實際測試過  資料庫密碼為 123  資料庫名稱為 技術通報資料庫.mdb
如果你仿照下面的代碼  不可以跑的話.....肯定是你的密碼之類的有問題......請把檔案 POST 上來

$conn = ObjCreate("ADODB.Connection")
$RS = ObjCreate("ADODB.Recordset")
$conn.Open ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=技術通報資料庫.mdb;Jet Oledb:Database Password=123 ");
$RS.ActiveConnection = $conn;
发表于 2012-2-7 09:23:44 | 显示全部楼层
不一定是这句错误,也许是上一句就有问题.
 楼主| 发表于 2012-2-7 11:29:02 | 显示全部楼层
是不是UDF的问题?,我这里找的access UDF
http://www.autoitx.com/forum.php ... hlight=access%2Budf
发表于 2012-2-7 13:04:49 | 显示全部楼层
回复 6# kimgmax

根本不需要用到UDF  ..............直接這樣就可以連線了...請把你的程式碼 POST 上來
 楼主| 发表于 2012-2-7 14:58:25 | 显示全部楼层
回复 11# kk_lee69


#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <DateTimeConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <IPAddressConstants.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <StatusBarConstants.au3>
#include <WindowsConstants.au3>
#include <GuiIPAddress.au3>
#include <GuiStatusBar.au3>
#include <GUIConstants.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <GuiDateTimePicker.au3>
#include <Date.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <windowsconstants.au3>
#include <comboconstants.au3>

Local $datadir = "C:\myproject\mydb.mdb"
_add_gui()
Func _add_gui();数据添加窗口
        $Form1 = GUICreate("", 550, 260)
    $Group1 = GUICtrlCreateGroup("", 8, 4, 533, 350)
    GUICtrlCreateLabel("记录日期:", 40, 32, 64, 17)
    GUICtrlCreateLabel("消费类型:", 40, 67, 64, 17)
        GUICtrlCreateLabel("消费金额:", 39, 102, 64, 17)
        GUICtrlCreateLabel("备注:", 39, 139, 64, 17)
    $Date_Input = GUICtrlCreateDate("", 112, 29, 137, 20)
    $Type_Input = GUICtrlCreateInput("", 112, 64, 137, 20)
    $Money_Input = GUICtrlCreateInput("", 112, 99, 137, 20)
        GUICtrlSetTip(-1,"必须输入金额数","提示:",1)
        $Remark_Input = GUICtrlCreateInput("", 112, 134, 393, 20)
        GUICtrlCreateLabel("(元)", 250, 103, 30, 17)
        GUICtrlSetColor(-1, 0xFF0000)
    $Removal = GUICtrlCreateButton("清除重填", 64, 189, 89, 25)
        GUICtrlSetBkColor(-1, 0xCAE1FF)
    $Determined = GUICtrlCreateButton("确定录入", 392, 189, 89, 25)
        GUICtrlSetBkColor(-1, 0xCAE1FF)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    GUISetState(@SW_SHOW)
    GUISetBkColor (0xCAE1FF)
    While 1
        $msg = GUIGetMsg()
        Select
                Case $msg = $GUI_EVENT_CLOSE
                                GUIDelete($Form1)
                                WinActivate("客户资料录入")
                                GUISetState(@SW_ENABLE, $Form1_1)
                                ExitLoop
                Case $msg = $Determined
                                $Date = GUICtrlRead($Date_Input)
                                $Type =  GUICtrlRead($Type_Input)
                                $Money =  GUICtrlRead($Money_Input)
                                $Remark =  GUICtrlRead($Remark_Input)
                IF $Date = "" Or $Type = "" Or  $Money = "" Or  $Remark = "" Then
                                   MsgBox(0,"提示:","客户资料不能为空,请认真填写!")
                                Else
                                _sql_add($Date,$Type,$Money,$Remark)
                                                                MsgBox(0,"成功:","客户资料录入成功!")                                                               
                                                            GUIDelete($Form1)
                                                                ExitLooP
                                                            MsgBox(0,"失败:","录入的资料已经存在,录入失败!")
                                EndIf
                Case $msg = $Removal
                                GUICtrlSetData($Date_Input,"")
                                GUICtrlSetData($Type_Input,"")
                                GUICtrlSetData($Money_Input,"")
                                GUICtrlSetData($Remark_Input,"")
                EndSelect
    WEnd
EndFunc

Func _sql_add($Date,$Type,$Money,$Remark);数据库添加用户函数
                $conn = ObjCreate("ADODB.Connection")
                $conn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & $datadir)
                $conn.Execute("insert into note (Date,Type,Money,Remark) values('"&$Date&"','"&$Type&"','"&$Money&"','"&$Remark&"')")
                $conn.close
EndFunc
 楼主| 发表于 2012-2-7 15:00:58 | 显示全部楼层
回复 11# kk_lee69


    在学习中,请多指教~
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-30 23:25 , Processed in 0.079001 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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