472,145 Members | 1,477 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,145 software developers and data experts.

Problem in Adding record in Database

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
1 1391
jhardman
3,406 Expert 2GB
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.

Similar topics

3 posts views Thread by VIJAY KUMAR | last post: by
6 posts views Thread by Ammar | last post: by
reply views Thread by Saiars | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.