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 March 3rd, 2006, 12:42 PM
Registered User
 
Join Date: Mar 2006
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Checking to see if record exists

Dreamweaver - ASP\Javascript - Access

Can someone please help me with a method for checking whether a record exists.

I have a table for entering pateients details and saving these to a table in an access databse. I am trying to work out the best way for the user entering the details. We cannot have duplicate patients records. Should provide a page for entering the hospital number which will then search the database and return a record if it exists or a blank form if it doesnt?

Can someone help me with the method and the code to support it.

Kind regards
Emma



Reply With Quote
  #2 (permalink)  
Old March 3rd, 2006, 08:27 PM
Wrox Technical Editor
 
Join Date: Dec 2005
Location: , , Canada.
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
Default

How to find out if a record already exists in a database, If it doesn't Insert A New Record: http://www.dmxzone.com/ShowDetail.asp?NewsId=4615

Here's a quick example from the link above:

<%
  Dim strSQL
  strSQL = "SELECT * FROM MyTable WHERE username = '" & _
            Request.Form("username") & "'"
  Set rs = db.Execute()

  If rs.EOF Then
    'Record does not exist
  Else
    Response.Write "Record exists"
  End If
%>

- A.Kahtava
Reply With Quote
  #3 (permalink)  
Old March 5th, 2006, 07: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

This will work if ALL the usernames are unique. IMO a bad example unless indeed you are using code to enforce unique user names when a user account is created.

Are you? If so the code above will work for you. If not Im sure not many people have the same email address. This is an example of a unique field that can be used.

Wind is your friend
Matt
Reply With Quote
  #4 (permalink)  
Old March 10th, 2006, 10:08 AM
Registered User
 
Join Date: Mar 2006
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi there thank you for your replies.

I was intending to use the patient nubmer as this is a unique field.

In terms of the code, how can i ask it to other things when it has searched the database?

For instance:

If rs.EOF Then
    Go to the data entry page
Else
    Show the record that exists already
End If
%>

Kind regards
Emma


Reply With Quote
  #5 (permalink)  
Old March 10th, 2006, 10:02 PM
Wrox Technical Editor
 
Join Date: Dec 2005
Location: , , Canada.
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Replace "Go to the data entry page" with:

response.redirect "YourDataEntryPage.asp"

Everything You Need to Know About Response.Redirect: http://pubs.logicalexpressions.com/P...cle.asp?ID=214

- A.Kahtava
Reply With Quote
  #6 (permalink)  
Old March 13th, 2006, 12:40 PM
Registered User
 
Join Date: Mar 2006
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for the link - I am still not sure where I would put this code within the page. This is the main form below.

Kind regards
Emma


    <h2>Please enter hospital number:</h2>
     <form action=".asp" method="get" name="search" id="search">
        <label>
        <div align="center"><br>
            <input name="hospitalNumber" type="text" id="hospitalNumber">
          <br>
<br>
        <input name="search" type="submit" id="search" value="Enter">
        </div>
        </label>
                  </form>

Reply With Quote
  #7 (permalink)  
Old March 14th, 2006, 02:39 AM
Wrox Technical Editor
 
Join Date: Dec 2005
Location: , , Canada.
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The <% %> delimiters mark the enclosed code as script code.
You can put this code in your HTML file.

Try it, put the following in your HTML code:
<% response.write "Hello World" %>

Here's a link to a good ASP Tutorial: http://www.w3schools.com/asp/default.asp

- A.Kahtava
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
Checking if a specific template exists sl0th XSLT 3 October 1st, 2006 03:14 AM
Checking a Database before Inserting a Record vbmazza VB Databases Basics 2 April 28th, 2005 07:23 AM
Record Exists hugh@kmcnetwork.com SQL Language 3 September 13th, 2004 02:36 PM
checking file exists on remote server pete_m Classic ASP Basics 11 August 2nd, 2004 02:35 AM
Checking for duplicate record in jsp Regornil JSP Basics 0 July 30th, 2004 01:55 AM



All times are GMT -4. The time now is 05:15 AM.


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