0

Dear All !
I have a table titled
Customer_DETAIL
I want to check
and make sure That
there are no other
records in the table
that have
The same CustomerID .
The CustomerID are
FK's From customer table.
How can I check
for duplicates so
they do not create
duplicate records. And show that "CUSTOMER RECORD Already Exist"
I am using Visual
Basic .net and SQL
server 2005
database.
Plz write a code for saving record in vb.net.

THANK A TON !

4
Contributors
3
Replies
9
Views
4 Years
Discussion Span
Last Post by daniel955
0

I'm not sure if this is what you need but in your query use

SELECT DISTINCT CustomerID
FROM Customer_DETAIL

If there were any dupes DISTINCT will get rid of them at query time

0

First create A unique index of customerID in the foreign table customer_detail
I used the name IX_CustomerID for the unique index in my sample
then use the code below to catch the duplicate entry error.

Try
    'Do insert here
Catch ex As Exception
     If (ex.Message.IndexOf("IX_CustomerID") >= 0) Then 
         'IX_CustomerID is the name of your unique Index
         'If the message contains the word "IX_CustomerID"
         'That means a duplicate is found, thus display the message...
         MsgBox("Customer ID already exists.") 
     Else
         'Other errors go here like, no connection, etc...
         MsgBox("An error occured: " & ex.Message) 
     End If
End Try
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.