ASALAM ALIKUM Dear !...
I'm doing INVENTORY
PROJECT...
I'm using Ms sql 2005 as
BACK-END...
My tables are PURCHASE
and SALES...
In PURCHASE table,
fields are CODE(primary
key), PRICE, DATE,
TOTAL, QTY...
when I'm entering
datas in form and when
i click submit, the data
stored on database...
but when i enter same
DATA(CODE), it is
showing error...
i don't want to show
the DEFAULT ERROR
message...
so, i want to search
whether the CODE is
already in database or
not...
i.e When i click SUBMIT
button, 1st it has to
search whether the
CODE is already Exist
in table or not. if it is
not there, DATA have
to be saved. otherwise,
it has to DISPLAY
MESSAGE BOX that Record Already Exist.

Thanks in advance.

Searching for duplicates is built in your sql provider

Run this query

ALTER TABLE <table_name>
 ADD CONSTRAINT <constraint_name>
 UNIQUE(<column_name>)

then you can use try catch

Try
    'Initialize factory, connectionstring, adapter, command , etc.
    doInsert()
Catch ex As Exception
      If ex.Message.IndexOf("IX_code") Then
        MsgBox("Duplicate data entry found")
      Else
        MsgBox("An unexpected error occured: " & ex.Message)
      End If
End Try

Note IX_code is the constraint_name used in the above sample query

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.