如何判断在传统ASP中使用ADO调用SQL Execute()是否失败

Rob*_*gal 4 sql asp-classic

我有以下缩短的经典ASP代码,使SQL插入调用...

cmd.CommandText = "insert into MyTable values(blah, blah, blah)"   
cmd.CommandType = adCmdText

Set rs = cmd.Execute()
Run Code Online (Sandbox Code Playgroud)

使用Execute()返回的记录集如何判断插入是否成功?

CRe*_*lts 8

检查Err对象

cmd.CommandText = "insert into MyTable values(blah, blah, blah)"   
cmd.CommandType = adCmdText
On Error Resume Next
Set rs = cmd.Execute()
If Err.number<>0 or  objConnection.Errors.Count <> 0 Then
   'Do something to handle the error
End If
On Error Goto 0
Run Code Online (Sandbox Code Playgroud)

还可以在15秒内查看此链接