使用VBScript成功执行sql时返回数据库消息 [英] return database message on successful sql execution using VBScript

查看:275
本文介绍了使用VBScript成功执行sql时返回数据库消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用vbscript成功执行sql语句后,我需要捕获sql消息。这是我的代码。

I need to capture sql message upon successful execution of sql statement using vbscript. Here is my code.

Public Function ExecuteAPI_String(sql_Statement)
Dim num 
On Error Resume Next
Set objRecordSet = objConnection.Execute sql_Statement,num,adExecuteNoRecords
If Err.Number <> 0 Then
    ExecuteSQLStatement_String = Err.description
    objRecordSet.Close
    Err.Clear
Else
    ExecuteAPI_String = num & "records were affected"
    objRecordSet.Close
End If


推荐答案

这里的问题是使用 On Error Resume Next ,因为这将导致任何跳过错误的语句并设置 Err 对象。如果您注释掉错误恢复下一个 $ c>,您将看到实际错误,与执行此行的SQL查询无关;

The problem here is the use of On Error Resume Next because it will cause any statement that errors to be skipped and set the Err object. If you comment out the On Error Resume Next you will see the actual error which will be nothing to do with the execution of your SQL query as this line;

Set objRecordSet = objConnection.Execute sql_Statement,num,adExecuteNoRecords

不是有效的语句,因为该方法需要用方括号括起来;

isn't a valid statement as the method needs to be surrounded by brackets like this;

Set objRecordSet = objConnection.Execute(sql_Statement, num, adExecuteNoRecords)

您还需要确保您传递给 Execute()方法的所有值都是有效的(例如 adExecuteNoRecords

You will also need to make sure that all the values you're passing to the Execute() method are valid (such as adExecuteNoRecords being correctly defined).

确定行正确执行后,就可以取消注释 On Error Resume Next

Once you're sure the line is executing correctly, then you can uncomment the On Error Resume Next.

这篇关于使用VBScript成功执行sql时返回数据库消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆