preventing a record with the same name being added

Results 1 to 2 of 2

Thread: preventing a record with the same name being added

  1. #1
    Join Date
    Dec 1969

    Default preventing a record with the same name being added

    Hi,<BR><BR>I am allowing a user to add a record to a database table via a web page form. However need a way of preventing them from adding a record with the same name. Need a message to come up and tell them the record already exist.<BR><BR>I do not want to use a unique primary key to trap the user. Need to check the record name being added instead.<BR><BR>hope you can help<BR><BR>cheers<BR><BR>Mark<BR><BR><BR>

  2. #2
    Franco Guest

    Default Roses are red, violets are blue....

    You could set up a stored procedure which looks like:<BR><BR>CREATE PROC NameCheck<BR>(@Name varchar(255))<BR>AS<BR>SELECT Name FROM MyTable WHERE Name=@Name<BR><BR>If you pump in the @name parameter before adding a record, you can check for duplicates like:<BR><BR>strSQL="EXEC NameCheck @Name=" & Name &#039as supplied by user<BR>MyRs=strSQL,MyConnection<BR>If Not(MyRs.EOF) Then<BR>&#039There is already a name like this on the database. <BR>&#039Insert appropriate code.<BR>End If<BR><BR>Don&#039t forget to use Upper or Lower if you want to check the name regardless of case.<BR><BR>F.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts