Vb.Net - ExecuteNonQuery Duplicate

Good Day Experts!

I have a Vb.Net application that I am trying to improve the processing speed.  It takes too long to finish when many records in the textfile.

Currently I query the database checking for the keyed value before doing the insert if no duplicate. If I empty the database and take off the Duplicate check it is waaaay faster.

Is it possible to just execute the NonQuery insert...does the system return a distinct error message if keyed value found which I can check for and then bypass to the next record?

Thanks for your ideas,
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ste5anSenior DeveloperCommented:
Do you need a message for each row? How big are those files?

Normally I would import the entire file into a staging table. Then you can use
INSERT INTO DestinationTable
SELECT ColumnList
FROM StagingTable S
INNER JOIN DestinationTable D ON D.PrimaryKeyColumns = S.PrimaryKeyColumns
WHERE D.APrimaryKeyColumn IS NULL;

Open in new window

This will copy only the new rows. When your duplicate check involves more than the primary key columns, then include them in the JOIN condition.
You can check for duplicates and insert the row within a same query using something like below

If Not Exists (Select ColumnName From TableName Where ColumnName=Value)
   Insert Into ...

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jimbo99999Author Commented:
I awarded both contributors with the points since my question was abandoned...we are understaffed and I did not get back to this project in time.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.