Results 1 to 2 of 2

Thread: How do I catch this exception?

  1. #1
    blacksaibot is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Mar 2012
    Posts
    8
    Reputation
    0

    How do I catch this exception?

    System.Data.OleDbException (0x80004005): The changes you requested to the table were not successful because they would create duplicate values in the index, primary key..."


    I know how to catch all exceptions. But I want to catch THIS SPECIFIC ONE so I can call one of my subroutines to generate a different ID that will not violate the primary key.


    One TEMPORARY solution I've already applied was to query the database to find all existing distinct IDs, and them to a list, and continuously generate an ID that hasn't been used yet by checking if the list .contains it already (via a do while loop). However, I don't want to create a data type that could possibly house thousands of IDs.


    Thanks in advance!

  2. #2
    Herman is offline VB.NET Forum Miyagee
    .NET Framework
    .NET 4.0
    Join Date
    Oct 2011
    Location
    Montreal, QC, CA
    Posts
    450
    Reputation
    347
    Try
    ...
    Catch ex As System.Data.OleDbException
    Select Case ex.Number
    Case ...
    ...
    Case Else : Throw
    End Select
    End Try

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking