Go Back   CodingForums.com > :: Server side development > ASP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-15-2004, 09:49 PM   PM User | #1
Number_Nineteen
New to the CF scene

 
Join Date: Jul 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Number_Nineteen is an unknown quantity at this point
Clearing a "catch" error value in a loop (JScript)

I have a loop that includes a try/catch. The loop is checking if a DB insert succeeded or failed. What happens is that if the first INSERT succeeds, the catch does not execute (which is the expected behavior). The problem is that if any INSERT fails, the remaining INSERTS report failure because the catch error number from the failed INSERT is not clearing at each loop. So, potentially, the next INSERT following a failed INSERT could have succeeded, but the report signifies it has failed. Confusing?

http://www.c1.cc/v2/recipient_mgr.asp

First, submit the form as it is. You will see 5 failures, because the 5 records already exist in the DB. Then, go back to the form and change one or two form fields in the middle. See what happens.

Code:
<% if (Request.querystring("s") != "") {
	RSQL = "SELECT * FROM Recipients"
	var R = Server.CreateObject("ADODB.Recordset");
    R.Open(RSQL, Conn, 3, 3);
	
	counter = 0;
	var e = new Enumerator(Request.Form)
	while (!e.atEnd(e)) {
		try {
			x = 0;
			counter++
			i = e.item()
			if (i.replace("_" + counter,"") == "EmailAddress") {
				R.AddNew
				R("RecipientEmailAddress") = Request.Form(i)
				R.Update
			}
		} catch(theError) {
			x = theError.number
		}
		
		if (x != 0) {
			Response.Write(counter + ". " + "FAILURE<br>");
		} else {
			Response.Write(counter + ". " + "SUCCESS<br>");
		}
		e.moveNext()
	}
}
%>
Number_Nineteen is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:57 PM.


Advertisement
Log in to turn off these ads.