Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL ADO Execute Method 1

Status
Not open for further replies.

itflash

Programmer
Jul 18, 2001
535
GB

Hi all

Another question

How can I trap for an error from the execute method? See below. I tried "If Err", but it didnt work.

Also, can I encase multiple execute methods into a begintrans?


Thanks
[spin] ITFlash [spin]


Check if a user was selected and if delete was pressed
' If so, delete the appropriate user

if isnumeric(request.form("userlist")) and _
not isempty(request.form("delete)) then
connectionstring = "DSN=sql-db;UID=;PWD="
set sqldb = Server.CreateObject("ADODB.Connection")
sqldb.CommandTimeout = 1000
sqldb.open ConnectionString
cSql = _
"DELETE FROM iuser WHERE userid=" & _
rtrim(request.form("userlist1")) & ";"
sqldb.Execute (cSql)
end if
 
RE: Error trap - Did you enable error handling with the On Error statement?
RE: multiple execute methods in a begintrans - Yes. That's what a transaction is for, making a series of changes appear as just one.

Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open "MyConnString....."
If oConn.State <> 1 Then
Response.Write &quot;Could not connect&quot;
Else
On Error Resume Next
Err.Clear
oConn.Execute &quot;Select * from yo&quot;
If Err.Number <> 0 THen
MsgBox Err.Description
' or use the errors collection: oConn.Errors(0).Description
end if

oConn.BeginTrans
oConn.Execute &quot;INSERT INTO....&quot;, nRecords
If nRecords >= 1 Then
nRecords = 0
oConn.Execute &quot;INSERT INTO....&quot;, nRecords
If nRecords >= 1 Then
oConn.CommitTrans
Else
oConn.RollbackTrans
End If
Else
oConn.RollbackTrans
End If
oConn.Close
On Error Goto 0
End If
Set oConn = Nothing Jon Hawkins
 

Thanks for the reply.....but.....

...whats the difference between:

If Err Then

and

If Err.Number <> 0 Then

Thanks
ITFlash

 
IIRC, there's no difference AFA functionality. Although the former is shorter and easier to code, I'd recommend you use the latter because it's more explicit - making it more maintainable & reliable. Jon Hawkins
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top