• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 437
  • Last Modified:

Prevent Duplicate Records on "Insert" .NET 2.0 Detailsview web application

Hi Expert:

I have a .NET 2.0 guestbook like application that untilizes a std "DetailsView"  control webpage ( ) .

User enter's his or her name, email address and employee#  and clicks a button labelled "INSERT"
to enter "sign-up"  data record ( one at a time) into the SQL Server.


THe only code is one simple "INSERT INTO TABLE .......... firstname,lastname, etc    "


The problem here is the user can possiblily add themselves more then once to the guest list.

How do the pro's prevent duplicate records entering in SQL server.

Is there something simple that can be done to prevents ( a  key on database etc) .

What do I have to do here to prevent possible duplicate records?

Help.
0
RSSIAdmin
Asked:
RSSIAdmin
  • 3
1 Solution
 
Aneesh RetnakaranDatabase AdministratorCommented:
if you have a Primary key, then it is possible
While inserting it will give some error, you can handle the error at the front end  or change the query to check some condititon

insert into urtable ......
where not exists (select 1 from urtable where Primarykeyvalue = 'urmanuallyenterredValue')
0
 
RSSIAdminAuthor Commented:
I knew a pro would know how to do this.  Thank you!!!!!!!!

I think I understand but just to make sure.

My 1 single table looks something like this:

Table 1
(primary key)  person_ID       int
                     First_Name      varchar(50)
                     Last_Name       varchar(50)
                     Pay_Number     varchar(50)   <--------- one unique paynumber per person
                        etc..                 etc..

Using  --> Pay_Number   (unique paynumber per person)

WOULD MY INSERT STATEMENT LOOK LIKE THE FOLLOWING

INSERT INTO Table 1 (First_Name, Last_Name,........etc
WHERE NOT EXIST (Pay_Number = @userinputpaynumber)

Sorry I am not a DB person, could you kindly please look over above and advise if this is what you mean

Again, thank you (please advise)
0
 
RSSIAdminAuthor Commented:


My 1 single table looks something like this:

Table 1
(primary key)  person_ID       int
                     First_Name      varchar(50)
                     Last_Name       varchar(50)
                     Pay_Number     varchar(50)   <--------- one unique paynumber per person
                        etc..                 etc..

Using  --> Pay_Number   (unique paynumber per person)

WOULD MY INSERT STATEMENT LOOK LIKE THE FOLLOWING ( my user input textbox values @First_Name,...@Pay_Number ) :

INSERT INTO Table_1 (First_Name, Last_Name,........etc)  VALUES (@First_Name,(@Last_Name,...@Pay_Number)
WHERE NOT EXIST (SELECT Pay_Number FROM Table_1  WHERE person_ID =  'Pay_Number')

Sorry I am not a DB person, could you kindly please look over above and advise if this is what you mean!!!

Again, thank you (please advise)
0
 
RSSIAdminAuthor Commented:
Thank you aneeshattingal for your welcomed advise


However, I still not sure if  the following is correct ?

INSERT INTO Table_1 (First_Name, Last_Name,........etc)  VALUES (@First_Name,(@Last_Name,...@Pay_Number)
WHERE NOT EXIST (SELECT Pay_Number FROM Table_1  WHERE person_ID =  'Pay_Number')



Again, thank you
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now