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 March 3rd, 2006, 12:42 PM
Registered User
 
Join Date: Mar 2006
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



 
Old March 3rd, 2006, 08:27 PM
Wrox Technical Editor
 
Join Date: Dec 2005
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
 
Old March 5th, 2006, 07:02 PM
Friend of Wrox
 
Join Date: Jan 2004
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
 
Old March 10th, 2006, 10:08 AM
Registered User
 
Join Date: Mar 2006
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


 
Old March 10th, 2006, 10:02 PM
Wrox Technical Editor
 
Join Date: Dec 2005
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
 
Old March 13th, 2006, 12:40 PM
Registered User
 
Join Date: Mar 2006
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>

 
Old March 14th, 2006, 02:39 AM
Wrox Technical Editor
 
Join Date: Dec 2005
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





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 [email protected] 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





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