By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,669 Members | 2,546 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,669 IT Pros & Developers. It's quick & easy.

Problem in Adding record in Database

P: 2
Hi dears,

I am adding a record in Access database using AddNew method of recordset. here is the code of the page ..
Expand|Select|Wrap|Line Numbers
  1. <%
  2.         Set RsLibBuild = Server.CreateObject ("ADODB.Recordset")
  3.         RsLibBuild.ActiveConnection = conn
  4.         RsLibBuild.LockType = 2
  5.         RsLibBuild.CursorType = 1
  6.  
  7.         RsLibBuild.Open "select * from tblbuilding where building_name='" & request.Form ("buildingname") & "' and area_name='" &  request.Form ("areaname") & "' and city_name='" & request.Form ("cityname") & "' and lib_status='1'"
  8.  
  9.             if RsLibBuild.EOF or RsLibBuild.BOF then
  10.  
  11.  
  12.                 RsLibBuild.AddNew
  13.                 RsLibBuild ("building_name") = Request.Form ("buildingname")
  14.                 RsLibBuild ("area_name") = Request.Form ("areaname")
  15.                 RsLibBuild ("city_name") = Request.Form ("cityname")
  16.                 RsLibBuild ("description") = Request.Form ("thecontent")
  17.                 RsLibBuild ("lib_status") = "1"
  18.                 RsLibBuild ("dated") = date
  19.                 RsLibBuild ("timed") = time
  20.                 RsLibBuild ("logby") = session("uname")
  21.                 RsLibBuild.Update                
  22.  
  23.                 RsLibBuild.Close
  24.                 set RsLibBuild = nothing
  25.  
  26.                 Msg = "1 Record Added .... "
  27.                 Response.Redirect "buildingsnap.asp?id="& request.Form("buildingname") &"&ConfMsg="&Msg
  28.  
  29.             else
  30.  
  31.                 RsLibBuild.Close
  32.                 set RsLibBuild = nothing
  33.  
  34.                 Msg = "Record already exists ....  "
  35.                 Response.Redirect "addlibbuilding.asp?ErrMsg="&Msg
  36.  
  37.  
  38.             end if
  39.  
  40.  
  41. %>
In ideal scenrio of database entry the page shud be redirected to buildingsnap.asp with Msg "1 Record Added..." but its happening reverse and data is being added in the database but after RsBuilding.update it goes to the else part and redirect to addlibbuilding.asp with Msg "Record Already Exist".

Record is being added but redirection of page is wrong. If i comment the RsBuilding.update line in above mentioned code then it works fine and redirect propery.

A quick response will be highly appreciated..

Thanx in adv.

Raaaz
Sep 19 '07 #1
Share this Question
Share on Google+
1 Reply


jhardman
Expert 2.5K+
P: 3,405
You definitely wrote this code correctly. In any given time through this script it will not go through both the if and the else clause, so it must be going through this script twice from what you've told us. I would guess that perhaps buildingsnap.asp is redirecting back here, that would explain why you go into the else clause.

Jared
Sep 20 '07 #2

Post your reply

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