Results 1 to 3 of 3

Thread: Overwrite data in DB

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2000
    Location
    hongkong
    Posts
    251
    Dear My Friends,

    I wish to ask a question about updating data in a MS Access database which I use ADO for connecting.

    Suppose my program allows the use to import data from a delimited text datafile and the primary key of the database is

    stockcode;date

    If the user click the import button twice, the error (-2147467259) will occur:

    "The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again."

    So I wish to trap this error and prompt the user whether to overwrite the existing data item or cancel the insertion. I also wish to provide a checkbox "ALL" to allow the user to overwrite all data or just keep all existing data unchanged.

    So can anyone give me some coding hints on how I can achieve this purpose. Thanks a lot.

  2. #2
    Junior Member
    Join Date
    Feb 2001
    Location
    Central IL
    Posts
    23
    I would suggest against using a date as your key, but without knowing everything you are doing it's hard to say for sure.

    With you using the term "trap" this error, I assume you know how to trap/ignore an error and then act on that?
    Bill

  3. #3
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Sydney Australia
    Posts
    804
    Why don't you set it up so that the code deletes all the records in the table before you import the data, this way you won't have to fiddle around with a messy error handler.

    You might not be able to do this due to some other factor, but it is just a thought...

Posting Permissions

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



Click Here to Expand Forum to Full Width