|
本帖最后由 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[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
错误提示:
>"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 完成[CODE]: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 完成:[CODE]: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 1 CPU:X64 系统架构:X86 语言环境:0804
+> SciTE 目录 => C:\Program Files\AutoIt3\SciTE AutoIt3Wrapper 用户目录 => 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\AutoIt3 au3 文件: 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 |
|