is this dodgy.. error checking

Results 1 to 2 of 2

Thread: is this dodgy.. error checking

  1. #1
    Join Date
    Dec 1969

    Default is this dodgy.. error checking

    i am looping through a for loop and doing multiple inserts... however about half the fields already have a value so i am checking for a primary key violation, and doing an update if one exists... it is working perfectly... but i was wondering if it is bad coding???<BR><BR>the part of the code which is doing error checking looks like this. remember it is in a loop so this might be running up to about 50 times..<BR><BR>objConn.Errors.Clear &#039; be safe and clear existing errors<BR> On Error Resume Next<BR> objConn.execute("INSERT INTO tblPositionTrack (tmID, tmPositionID, tmQTY) VALUES (" & tID & "," & poID & "," & poQTY & ");") <BR> &#039;check if there were any errors<BR> if err.number &#060;&#062; 0 then<BR> if err.number = -2147217900 then<BR> objConn.execute("UPDATE tblPositionTrack SET tmQTY = "& poQTY &" WHERE tmID = " & tID & " AND tmPositionID = "& poID & ";")<BR> else<BR> response.write "an error occured"<BR> end if<BR> end if<BR> on error goto 0 <BR>

  2. #2
    Join Date
    Dec 1969

    Default Only one part looks bad...

    You don&#039;t bother to check if the *second* objConn.Execute might have gotten an error!<BR><BR>Also, *some* database errors do not get properly propagated back to the ERR object, so be sure to test this to make sure the error you are looking for does get there. (If not, you&#039;ll have to use the ADODB.Connection.Errors collection, instead.)<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts