468,309 Members | 1,107 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,309 developers. It's quick & easy.

Improper response.redirect after objConn.execute

21
Hi, this is my first post but I've been constantly referred to this site when I needed help. Anyway, this time I can't seem to find anything, so here goes.

This is part of my case statement, and I can't figure out why it's having problems. When I use objConn.execute after I check it's not EOF, I will get redirected to the condition that IS EOF, BUT the items is still properly deleted. If I comment out the execute statement, it redirects properly.

Sorry if it's obvious, but I seriously can't see WHY. I have similar code on another page and it works fine.

Thanks in advance!

Expand|Select|Wrap|Line Numbers
  1.     case "delete"
  2.  
  3.         cID = cInt(cleanString(request.QueryString("id")))
  4.  
  5.             set rs = Server.CreateObject("ADODB.Recordset")
  6.             SQL = "SELECT cName FROM class WHERE cID = " & cID
  7.             'response.Write(sql)
  8.             'response.End()
  9.             'Open connection
  10.             rs.Open SQL, objConn
  11.  
  12.             if rs.eof then
  13.  
  14.                 closeRS(rs)
  15.                 closeConn()        
  16.  
  17.                 response.Redirect("admin.asp?page=class" & "&statusMsg=failed") 'THIS LINE IS EXECUTED IF I USE objConn.execute IN THE NEXT SECTION
  18.                 response.End()    
  19.  
  20.             else
  21.  
  22.                 'objConn.open
  23.                 objConn.execute("DELETE FROM class WHERE cID=" & cID)
  24.  
  25.                 closeRS(rs)
  26.                 closeConn()
  27.  
  28.                 response.Redirect("admin.asp?page=class" & "&statusMsg=delOK") 'THIS LINE WON'T EXECUTE IF I USE objConn.execute
  29.                 response.End()
  30.  
  31.             end if
  32.  
  33.     'end case DELETE
Dec 12 '06 #1
6 3426
sashi
1,754 Expert 1GB
Hi, this is my first post but I've been constantly referred to this site when I needed help. Anyway, this time I can't seem to find anything, so here goes.

This is part of my case statement, and I can't figure out why it's having problems. When I use objConn.execute after I check it's not EOF, I will get redirected to the condition that IS EOF, BUT the items is still properly deleted. If I comment out the execute statement, it redirects properly.

Sorry if it's obvious, but I seriously can't see WHY. I have similar code on another page and it works fine.

Thanks in advance!

Expand|Select|Wrap|Line Numbers
  1.     case "delete"
  2.  
  3.         cID = cInt(cleanString(request.QueryString("id")))
  4.  
  5.             set rs = Server.CreateObject("ADODB.Recordset")
  6.             SQL = "SELECT cName FROM class WHERE cID = " & cID
  7.             'response.Write(sql)
  8.             'response.End()
  9.             'Open connection
  10.             rs.Open SQL, objConn
  11.  
  12.             if rs.eof then
  13.  
  14.                 closeRS(rs)
  15.                 closeConn()        
  16.  
  17.                 response.Redirect("admin.asp?page=class" & "&statusMsg=failed") 'THIS LINE IS EXECUTED IF I USE objConn.execute IN THE NEXT SECTION
  18.                 response.End()    
  19.  
  20.             else
  21.  
  22.                 'objConn.open
  23.                 objConn.execute("DELETE FROM class WHERE cID=" & cID)
  24.  
  25.                 closeRS(rs)
  26.                 closeConn()
  27.  
  28.                 response.Redirect("admin.asp?page=class" & "&statusMsg=delOK") 'THIS LINE WON'T EXECUTE IF I USE objConn.execute
  29.                 response.End()
  30.  
  31.             end if
  32.  
  33.     'end case DELETE
Hi there,

Kindly refer to below modified code segment, hope it works. Good luck & Take care.

Expand|Select|Wrap|Line Numbers
  1.   ..
  2.   ..
  3.   rs.Open SQL, objConn, 1, 3
  4.  
  5.   If rs.RecordCount > 0 Then ' Make sure table is not empty
  6.     If rs.EOF = True Then ' EOF is false
  7.       Response.Redirect "somepage.asp"
  8.       closeRS(rs)
  9.       closeConn()        
  10.     Else ' EOF is true
  11.       objConn.execute("DELETE FROM class WHERE cID=" & cID)
  12.       Response.Redirect "anotherpage.asp"      
  13.       closeRS(rs)
  14.       closeConn()        
  15.     End If
  16.   End If
  17.  
Dec 13 '06 #2
gyung
21
Thanks for your reply!
the recordcount property didn't work for me, so I used count(*), which worked fine. It finds a record, but I'm still getting redirected to the wrong place... I think i'll just have to use another way to validate it.

again if I remove the execute, it works fine. I'm guessing it's somehow running the script twice after execution. Thanks again!
Dec 13 '06 #3
gyung
21
Ok it's driving me nuts, I can't validate the entry before deleting properly AND have the successful message. I'll probably be the one managing the site and DB anyway, but from a programming standpoint i'm hung up about it >.<
Dec 13 '06 #4
iam_clint
1,208 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1.     case "delete"
  2.  
  3.         cID = cInt(cleanString(request.QueryString("id")))
  4.         set rs = Server.CreateObject("ADODB.Recordset")
  5.         SQL = "SELECT cName FROM class WHERE cID = " & cID
  6.         rs.Open SQL, objConn, 1, 2
  7.         if rs.eof then
  8.             closeRS(rs)
  9.             closeConn()        
  10.             response.Redirect("admin.asp?page=class&statusMsg=failed")
  11.             response.End()    
  12.         else
  13.             'objConn.open
  14.             objConn.execute("DELETE FROM class WHERE cID=" & cID)
  15.             closeRS(rs)
  16.             closeConn()
  17.             response.Redirect("admin.asp?page=class&statusMsg=delOK")
  18.             response.End()
  19.         end if
  20.     'end case DELETE
  21.  
heres my modified version for you... hope it works for ya but cId is a number correct is your cleanstring changing the variable to an int?
Dec 15 '06 #5
gyung
21
Hey thanks a lot. I was away for a while so I didn't check this...

Anyway the execute statements are being... executed.. before the if else statements. I found a workaround for that page by not closing the recordsets. I don't know why that works, but it does.

Sometimes validation in if else statements don't work though... Like for my update page for checking dates, my commands are being sent to the SQL server before anything else is evaluated.

Unless I specifically try using something such as response.write(SQL) followed by response.end(), it will complete execute first.

Why is it doing that??

Thanks again!
Dec 27 '06 #6
gyung
21
Ok...

I'm using

If (--) then
%><script>asdf</script><%
end if

so it's being execute along with the objConn.execute

I just put a response.End() behind the script and it works :)
Dec 27 '06 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Jed | last post: by
10 posts views Thread by isaac2004 | last post: by
2 posts views Thread by Shawn Convington | last post: by
3 posts views Thread by Mark Huebner | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.