How is it that you know the primary key before you insert the record? Are
you using some part of the business information as the primary key?
If this is the case, then as soon as the user has entered the PK info, you
should look up the data and show it to the user. Let them know that the
record exists and that they can update it if they'd like.
Also: it is a good idea not to use business data as part of the primary key.
--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik
Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"Joey Lee" <an*******@discussions.microsoft.com> wrote in message
news:24****************************@phx.gbl...
Hi,
I was wondering which is the best way of checking if a
record exist in the database before inserting.
There are quite a few ways I have seen. Here are some...
1> Insert and hit a primary key violation and then handle
it
2> Select of a dataset/datareader based on the new record
id. If the result has something in it, then don't insert
3> Change the sql statement to count(*) based on the new
record id. If count > 0 then don't insert
So, I was wondering which is the best way(most effecient
way) of doing it. or if there are better way.
Thanks
Joey