$RS.Fields (1).value 错误。
本帖最后由 sunkiss 于 2016-3-23 22:56 编辑学习【原创】AU3 操作SQL 数据库…详细语法、参数…教学 课程(一) MSSQL入门http://www.autoitx.com/thread-30083-1-1.html
执行MsgBox(0, "???", $RS.Fields (1).value)时候提示错误。
"C:\Users\Administrator\Desktop\??1.5.au3" (109) : ==> ????? "With" ????.:
MsgBox(0, "???", $RS.Fields (1).value)
MsgBox(0, "???", $RS.Fields (1)^ ERROR
经过测试只要是.value的全部错误。
下面也是学习的一个代码,在我上面也报错。
点击用户名查询就报错,版本不同报错不同。
老版本使用的是3.3.9,新版本在虚拟机里测试的,使用最新的AutoIt_v3.3.14.2_Setup(3)。#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='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)
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 & " setname='"&$read1&"',pass='"&$read2&"' WHERE id" & " = " & $Strnspin)
$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
$addfld.execute($sQuery)
$addfld.close
read()
EndFunc
错误提示:
>"D:\autoit3\SciTE\ACNWrapper\ACNWrapper.exe" /run /ErrorStdOut /in "D:\文档库\下载\数据库基础.au3" /autoit3dir "D:\autoit3" /UserParams
+>22:39:14 开始执行 ACNWrapper v.1.0.1.1
+> ============================================
+>执行环境:
+> CPU构架: X64
+> 系统构架: X64
+> 系统语言: 0804
+> 键盘布局: 00000804
+> 内存总量: 8115MB
+> 内存剩余: 2296MB
+> 操作系统: UNKNOWN
+> AU3版本: 3.3.9.0
+> ============================================
>运行 AU3Check (1.54.23.0)开始目录:D:\autoit3
+>22:39:14 AU3Check 完成:0
>运行:(3.3.9.0):D:\autoit3\autoit3_x64.exe "D:\文档库\下载\数据库基础.au3"
"D:\???\??\?????.au3" (94) : ==> ????? "With" ????.:
GUICtrlCreateListViewItem ( $RS.Fields (0).value&"|"& $RS.Fields (1).value&"|"& $RS.Fields (2).value,$ListView1 )
GUICtrlCreateListViewItem ( $RS.Fields (0)^ ERROR
->22:39:16 AutoIT3.exe 完成::1
+>22:39:17 ACNWrapper 完成..
>退出代码: 1 运行时间: 4.455 秒
最新版的报错:
>"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\Users\Administrator\Desktop\数据库基础.au3" /UserParams
+>22:54:25 启动 AutoIt3Wrapper v15.920.938.0 SciTE v3.6.0.0键盘:00000804操作系统:WIN_7/Service Pack 1CPU:X64系统架构:X86语言环境:0804
+> SciTE 目录 => C:\Program Files\AutoIt3\SciTEAutoIt3Wrapper 用户目录 => C:\Users\Administrator\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper SCITE 用户目录 => C:\Users\Administrator\AppData\Local\AutoIt v3\SciTE
>运行 AU3Check (3.3.14.2) 检查代码.参数: C:\Program Files\AutoIt3au3 文件: C:\Users\Administrator\Desktop\数据库基础.au3
+>22:54:26 AU3Check 语法检查结束.rc: 0
>运行:C:\Program Files\AutoIt3\autoit3.exe(3.3.14.2), 脚本: C:\Program Files\AutoIt3\autoit3.exe "C:\Users\Administrator\Desktop\数据库基础.au3"
--> 点击 Ctrl+Alt+Break 重新启动, 或 Ctrl+Break 停止脚本执行
"C:\Users\Administrator\Desktop\?????.au3" (88) : ==> ??????????.:
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path)
$addfld^ ERROR
->22:54:28 AutoIt3.exe 结束.rc: 1
+>22:54:28 AutoIt3Wrapper 完成脚本处理.
>Exit code: 1 Time: 3.165 回复 1# sunkiss
請提供 你測試的 程式碼以方便ˊ找問題 回复 2# kk_lee69
谢谢关注,帮我看看吧 本帖最后由 kk_lee69 于 2016-3-24 09:25 编辑
回复 3# sunkiss
強烈懷疑 是 新版檢查問題
你不要再 SciTE 按下執行
請使用 AutoIt3.exe 直接執行看看......
我看起來是沒甚麼錯誤 如果你那邊真的會出問題,可能要麻煩提供 MDB 檔案以方便實際執行看看
或者 試著 $RS.Fields(0).value中間不要有任何空白看看 $RS.Open ("Select * From "& $adTable & " WHERE name" & " ='"&$ipt3&"'")
$RS.Open ("Select * From "& $adTable & " WHERE name" & " ='"&$ipt3&"'",$addfld,3,3)
If $RS.RecordCount Then
试试 回复 1# sunkiss
代码不知那里有问题,简化后-MsgBox-就能提示
#include <Array.au3>
#include <Access.au3>
#include <GUIListView.au3>
#include <GuiImageList.au3>
#include <ListViewConstants.au3>
;#include <Access.au3>
$Form1 = GUICreate("Form1", 400, 381, 290, 255)
$Label3 = GUICtrlCreateLabel("用户名", 220, 8, 45, 17)
$Label4 = GUICtrlCreateLabel("密码", 220, 32, 40, 17)
$Input3 = GUICtrlCreateInput("aaa",270, 5, 121, 21)
$Input4 = GUICtrlCreateInput("",270, 29, 121, 21)
GUISetState(@SW_SHOW)
$ipt3 = GUICtrlRead($Input3)
MsgBox(48,'提示',$ipt3)
$mdb_data_path = @ScriptDir & "\tets.mdb";脚本所在目录下生成名为test。mdb的数据库
$adTable = "users";表名称
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd 回复 1# sunkiss
你的代碼 還有個問題
你太多的連接處理了.....
你每做一個動作 都是
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path)
但是 卻沒看到你把連結關掉
連結應該是一次就可以
中間得讀寫 新增刪除修改 都不需要再 連接
最後退出 程式 關閉連接 回复 1# sunkiss
查到了,
27行,28行
$Input3 = GUICtrlCreateInput("",270, 5, 121, 21)
$Input4 = GUICtrlCreateInput("",270, 29, 121, 21)
34行,35行
$Input3 = GUICtrlCreateInput("",270, 100, 121, 21)
$Input4 = GUICtrlCreateInput("",270, 129, 121, 21)
重复,查询时无法判断. 回复 8# chzj589
查询可改为:
$ipt3 = GUICtrlRead($Input5)
MsgBox(48, '提示', $ipt3)
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)
$RS.open("SELECT * FROM " & $adTable & " WHERE name='" & $ipt3 & "' OR pass='" & $ipt3 & "'")
;$RS.Open ("Select * From "& $adTable & " WHERE name'" & $ipt3 & "'OR pass='" & $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
谢谢给位了,我这几天出差,没看到,一会试试。
页:
[1]