How to find out if an SQL Execute () call caused ADO to be used in classic ASP

I have the following shorthand classic ASP code that calls an SQL insert call ...

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

Using the recordset that Execute () returns, how can I tell if an insert was successful or not?

+4
source share
2 answers

Check out the Err object

 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 

Also take a look at this link at 15Seconds

+7
source

If you do not want to check for errors, you can:

 cmd.CommandText = "insert into MyTable values(blah, blah, blah) SELECT @@Rowcount" cmd.CommandType = adCmdText Set rs = cmd.Execute() RecordsAffected = rs(0) 

In the same law, if you have an identifier column, you can get the identifier obtained using

 cmd.CommandText = "insert into MyTable values(blah, blah, blah) SELECT @@Identity" cmd.CommandType = adCmdText Set rs = cmd.Execute() NewID = rs(0) 
+3
source

Source: https://habr.com/ru/post/1303024/


All Articles