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
Register
| 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
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 10th, 2005, 04:01 AM
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 duplicate entry of records

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

Reply With Quote
  #2 (permalink)  
Old February 10th, 2005, 06:32 AM
Friend of Wrox
 
Join Date: Oct 2003
Location: Chennai, TamilNadu, India.
Posts: 326
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Santhi Send a message via MSN to Santhi
Default

You were getting errors because you have used Response.Form in the string as it is.You should have appended like this
sql_insert = sql_insert & " where Bldgname <> ("+Request.Form("BldgnameNew")+")"

To avoid duplicate entry ,
   Write one more select * query to the see the record Bldgname exists.If it is not 0,then throw an javascript alert script.


Reply With Quote
  #3 (permalink)  
Old February 10th, 2005, 06:39 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: , , United Kingdom.
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

AFAIK you cannot use a WHERE clause in an insert query.

Chris

Reply With Quote
  #4 (permalink)  
Old February 10th, 2005, 09:02 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

As Chris said you can not use a where condition like that. In addition Santhi's suggestion of:

sql_insert = sql_insert & " where Bldgname <> ("+Request.Form("BldgnameNew")+")"

If it were possible should be changes to:

sql_insert = sql_insert & " where Bldgname <> '" & Request.Form("BldgnameNew") & "';"

Note:
1.. the + replaced with &
2.. The single double quotes around the form element (if the value is a string)
3.. BTW : the semi colon at the end and my removal of the brackets is my personal style. The query would work without the semi colon (IMO should be used), It would also work with the brackets.

Wind is your friend
Matt
Reply With Quote
  #5 (permalink)  
Old February 10th, 2005, 09:14 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

One method to get around your problem:

Dim recordPresent
recordPresent = false
IF request.form("someName") <> "" THEN
   'check for an existing duplicate
   sql = "SELECT .... Where [existing val = new val];"
   set checkInfo = conn.execute(sql)
   if checkInfo.EoF then
      'not found so insert
       sql = "INSERT INTO....;"
       conn.execute(sql)
   else
      'duplicate found so dont insert
      recordPresent = true
   end if
end if

Now in your page somewhere detect:

if recordPresent = true then
   Some message saying did not insert, record already present
end if

Additionaly:
;;;then throw an javascript alert script
You have to go to the server to check is the record there, I wouldnt use a JS alert myself.

Wind is your friend
Matt
Reply With Quote
Reply


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
Check for Duplicate Records in Data Entry Form roznix Access VBA 5 June 7th, 2012 08:53 AM
How Do I avoid duplicate values xsltier XSLT 3 June 4th, 2008 01:36 PM
avoid adding duplicate records in access/asp mikersantiago Classic ASP Basics 1 September 21st, 2004 03:24 AM
Avoid duplicate node values nambati XSLT 1 September 8th, 2004 02:41 PM
deleting only 1 duplicate entry qwjunk Classic ASP Databases 3 February 2nd, 2004 11:45 AM



All times are GMT -4. The time now is 12:07 PM.


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