老问题了,我原来就遇到过,也没人难帮助解决!
最后是使用变通的方法处理的!
我的代码Global $objErr=""
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc") ; Install a custom error handler
Func MyErrFunc()
$objErr = $oMyError.Description
; $oMyError.scriptline
;SetError ( hex($oMyError.Number,8), $oMyError.scriptline)
EndFunc
Dim $Cn1 = ObjCreate("Adodb.Connection")
With $Cn1
.Provider = "Microsoft.Jet.OLEDB.4.0;"
.ConnectionString = "Data Source=" & @ScriptDir & "\db1.mdb;"
.CursorLocation = 3 ;3=adUseClient
.Open
;删除记录
AdoDbExeCute( $Cn1, "DELETE FROM [XXB] WHERE 1=1" )
Switch @Error
case 0
msgbox( 64, "删除数据", "删除记录 " & @extended & " 条!" )
case 1
msgbox( 48, "提示", "未能创建对象! ")
case 2 ;'sql 出错
msgbox( 48, "提示", "动态SQL出错! " & $objErr)
case else
msgbox( 48, "提示", "执行遇到错误! ")
EndSwitch
;导入文本
AdoDbExeCute( $Cn1, "INSERT INTO [xxb1] SELECT * FROM [Text;DataBase="& @ScriptDir &"].[xxb.txt] ") ;WHERE 类别=106" )
Switch @Error
case 0
msgbox( 64, "导入数据", "导入记录 " & @extended & " 条!" )
case 1
msgbox( 48, "提示", "未能创建对象! ")
case 2 ;'sql 出错
msgbox( 48, "动态SQL错误", $objErr)
case else
msgbox( 48, "提示", "执行遇到错误! ")
EndSwitch
.Close
EndWith
Func AdoDbExeCute(ByRef $Cnn, byRef $strQuery )
;Dim $vba = ObjCreate("MSScriptControl.ScriptControl") ;与下面效果相同
Local $vbs = ObjCreate("ScriptControl")
Local $erl, $rec
If (IsObj($Cnn)=0 OR IsObj($vbs)=0) Then
Return SetError(1, 0, 0)
Endif
$vbs.Language = "VBScript"
$vbs.AddObject("cnn", $Cnn, false )
$vbs.AllowUI = false ;不显示接口UI
$vbs.ExecuteStatement('cnn.ExeCute "' & $strQuery & '", x ,1' )
$erl = $vbs.Eval("cnn.Errors.Count")
$rec = $vbs.Eval("x")
$vbs.reset
if $erl>0 then
return SetError(2, $rec, $rec)
Else
return SetError(0, $rec, $rec)
Endif
EndFunc
|