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 !

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

Make the CustomerID a primary key. That will prevent duplicate entries.

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.