Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 20th, 2004, 10:24 PM
Authorized User
 
Join Date: Sep 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mikersantiago
Default avoid adding duplicate records in access/asp

Hi guys,

Here are my existing asp pages,

1.profile_add_office.asp
<form method="POST" action="PROFILE_ADD_ac.asp" name="form" onSubmit="return validateForm(this)">
<input type="text" name="BldgnameNew" size="50">
'etc.

2.profile_add_ac.asp
BldgnameNew= ChkString(Request.Form("BldgnameNew"))
'etc.

sql_insert = "insert into TblSubgroup (Bldgname, cgroup, Datebuilt, GFA, GLA) values ('" & BldgnameNew & "','" & group & "', '" & Datebuilt & "', '" & GFA & "', '" & GLA & "', )"


I just want to ask how is it done in asp/access, to avoid duplicate or identical records to be added by the user in the database.

Here's exactly the scenario and what I want to happen with the application, I have a table in Access that holds records such as Bldgname, Datebuilt, Gross Floor Area (GFA), etc. Users can add new records (Bldgname, Datebuilt, GFA, etc.) but if the user enters the exact Building Name (Bldgname) that already exists in the database (i.e. Tower One - tower one), he will be prompted not to continue either by another asp page or a pop-up window, "Another record of the same building name already exists in our database, thank you.".

Can this be done by adding a condition in my sql insert statement such as...

sql_insert = "insert into TblSubgroup (Bldgname, cgroup, Datebuilt, GFA, GLA) "
sql_insert = sql_insert & " values ('" & BldgnameNew & "','" & group & "', '" & Datebuilt & "', '" & GFA & "', '" & GLA & "', ) "
sql_insert = sql_insert & " where Bldgname <> (Request.Form("BldgnameNew"))"

I'm getting errors when I tried the sql_insert above...
Expected end of statement in sql_insert.

Any other ways? Thanks a lot in advance to all of you :)



 
Old September 21st, 2004, 03:24 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 363
Thanks: 0
Thanked 1 Time in 1 Post
Default

hello,
  This one you can do in different ways.
1. Issue a query by conditioning with bldgid. If the recordset retrieves any records, means already exists. Stop executing Insert statement.


rs.open "tablename",conn
if not rs.BOF then
   rs.addNew
      rs.fields("bldgid")=request("txtBldgId")
      ....
   rs.update
else
  response.write "Already exists"
end if

rs.close


2. Add, on error resume next statement at the beginning of the script.
After conn.execute strSQl
  if Err.number = -2147467259 then 'error number for primary key violation
     response.write "ERROR! " & Err.description
  end if

---------
Rajani






Similar Threads
Thread Thread Starter Forum Replies Last Post
how to avoid duplicate values from the xml file us balasundarrao XSLT 2 June 4th, 2014 11:56 PM
How Do I avoid duplicate values xsltier XSLT 3 June 4th, 2008 01:36 PM
how to avoid duplicate contacts? combo box? dstein4d Access VBA 5 February 26th, 2008 05:55 PM
avoid duplicate entry of records mikersantiago Classic ASP Basics 4 February 10th, 2005 09:14 PM
Avoid duplicate node values nambati XSLT 1 September 8th, 2004 02:41 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.