return database message on successful sql execution using VBScript

元气小坏坏 提交于 2019-12-13 03:07:08

问题


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

回答1:


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)

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).

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



来源:https://stackoverflow.com/questions/46595963/return-database-message-on-successful-sql-execution-using-vbscript

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!