Executenonquery method

  • Thread starter Thread starter Marcel
  • Start date Start date
M

Marcel

Hi,

I'm trying to insert a number of records in a SQL server
table using the executenonquery method. This works fine
except when the records already exist which results in a
runtime error.

Is there a way to prevent this runtime error and just
ignore that the records can't be added ?

Thanks,

Marcel
 
hi marcel,
1) you can trap the exception that your SQL data provider
throws, and force the application to ignore the error -
and even rerun the query after discarding the duplicate
rows if necessary
2) there may be a way to use the SQL data objects within
asp.net to tell it to ignore duplicates upon insert - I'm
not sure, but think its worth a little research.

alex
 
Marcel,

Your query probably stops running when it hits the first error... so even if
you trapped and the disregarded the error on your code you wouldn't get
anything after what caused the error to insert.

You could try to write a sproc that executes inserts one a time and traps
the error and resumes internally. I assume when you said you are inserting
a number of records that you are doing a batch update. You could also try
to insert these one at a time from your app instead of in chunks.

Regards,
Jason S.
 
Back
Top