关于ACCESS的问题
#include <GuiConstantsEx.au3>#include <GuiListView.au3>
$mdb_data_path="D:\UserFile\Desktop\riftdata.mdb"
$tblname="acc"
$mdb_data_pwd="111"
$t="*"
$hListView=ControlGetHandle("客户端监控","","")
$hnu=_GUICtrlListView_GetItemCount($hListView)
$wnu=_GUICtrlListView_GetColumnCount($hListView)
Global $array[$hnu][$wnu]
For $i=0 To $hnu-1
$harray=_GUICtrlListView_GetItemTextArray($hListView,$i)
For $k=0 To $wnu-1
$array[$i][$k]=$harray[$k+1]
Next
Next
For $i=0 To $hnu-1
up($array[$i],$array[$i])
Next
Func up($data1,$data2)
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &$mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
$addfld.execute("update " & $tblname & " sety_stock='"&$data1&"',now_stock='"&$data1&"' WHERE role_name" & " = "&$data2)
$addfld.close
EndFunc
总是在最后一步出错,我看不出来哪里错了,希望高手指点一下 本帖最后由 水木子 于 2011-12-30 23:21 编辑
参数说明:
$adSource ;数据库路径
$adTable ;表
$sFieldNames;要更新的字段名
$sNewData ;新文本
$adQuery ;需要更新的项目ID
$DatabasePassword ;数据库密码
Func _UpdateData($adSource, $adTable, $sFieldNames, $sNewData, $adQuery, $DatabasePassword = '');更新数据
Local $sUpdateText
$aFieldNames = StringSplit($sFieldNames, '|')
$aUpdateText = StringSplit($sNewData, '|')
If $aFieldNames <> $aUpdateText Then Return 0
For $i = 1 To $aFieldNames
$sUpdateText &= $aFieldNames[$i] & '=' & "'" & $aUpdateText[$i] & "',"
Next
$sUpdateText = StringTrimRight($sUpdateText, 1)
$oADO = ObjCreate("ADODB.Connection")
$oADO.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $adSource & "; Jet OLEDB:Database Password=" & $DatabasePassword)
$oADO.execute("Update " & $adTable & " Set " & $sUpdateText & " WHERE ID" & " = " & $adQuery)
$oADO.close
EndFunc ;==>_UpdateData
还有什么问题可以看看下面的例子!不过没有做错误处理,全是以我自己的理解去写的,将就看吧!
有兴趣的朋友可以整理下。。
回复 2# 水木子
错误找出来了,是数据库语言里面的问题#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
$mdb_data_path="D:\UserFile\Desktop\riftdata.mdb"
$tblname="acc"
$mdb_data_pwd="111"
$t="*"
$hListView=ControlGetHandle("客户端监控","","")
$hnu=_GUICtrlListView_GetItemCount($hListView)
$wnu=_GUICtrlListView_GetColumnCount($hListView)
Global $array[$hnu][$wnu]
For $i=0 To $hnu-1
$harray=_GUICtrlListView_GetItemTextArray($hListView,$i)
For $k=0 To $wnu-1
$array[$i][$k]=$harray[$k+1]
Next
Next
For $i=0 To $hnu-1
up($array[$i],$array[$i])
Next
Func up($data1,$data2)
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &$mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
$addfld.execute("update " & $tblname & " sety_stock='"&$data1&"',now_stock='"&$data1&"' WHERE role_name" & " = '"&$data2"'")
$addfld.close
EndFunc正确的在上面,是数据库里面少了引号造成的,这样的错误还真不好找
页:
[1]