Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP Basics
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 20th, 2004, 10:24 PM
Authorized User
Join Date: Sep 2004
Location: Las Pinas, , Philippines.
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,

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

BldgnameNew= ChkString(Request.Form("BldgnameNew"))

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 :)

Reply With Quote
  #2 (permalink)  
Old September 21st, 2004, 03:24 AM
Friend of Wrox
Join Date: Sep 2003
Location: Mentiri, Muara, Brunei.
Posts: 363
Thanks: 0
Thanked 1 Time in 1 Post

  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
  response.write "Already exists"
end if


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


Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 02:38 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.