[已解决]连接access问题
本帖最后由 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
求助~~如何解决 $mdb_data_path你這個變數裡面的東西是甚麼 Local $mdb_data_path = "mydb.mdb"
Local $mdb_data_pwd = "123456" 我按网上查的例子写的,新手学习中~ 回复 3# kimgmax
加上絕對路徑看看............. 加过绝对路径,结果也一样 請先取消 資料庫的密碼先測試 可以過 然後在解決密碼的問題 回复 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; 不一定是这句错误,也许是上一句就有问题. 是不是UDF的问题?,我这里找的access UDF
http://www.autoitx.com/forum.php?mod=viewthread&tid=1200&highlight=access%2Budf 回复 6# kimgmax
根本不需要用到UDF..............直接這樣就可以連線了...請把你的程式碼 POST 上來 回复 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 回复 11# kk_lee69
在学习中,请多指教~
页:
[1]