rahavtom Posted September 23, 2004 Posted September 23, 2004 Hello ! My question is this: I add record to dataset using .AddNew command. Then I update this record with 'Begin Edit' and 'End Edit' commands, and finally I want to 'save' this record to the database (mdb file) using UPDATE command. When I do this, and in case that record with the same values (in key fields) is already exist in the database, I get an error message that the operation can't be done because it will create a duplicate key and so on.... before I perform the UPDATE command, I update the data adapter SELECT, UPDATE and DELETE commands with GetUpdateCommand, etc. How can I 'tell' the UPDATE command to perform an UPDATE action when record already exist, and to INSERET a new record when it doesn't ? Hope it's clear enough... Thanks, Tom. Quote
Moderators Robby Posted September 23, 2004 Moderators Posted September 23, 2004 An Update cmd needs a Where clause, in a sense you need to pin-point the exact record to update, Is this what you are currently doing? If the record already exists, is this not what you want? To update an existing record. Quote Visit...Bassic Software
rahavtom Posted September 24, 2004 Author Posted September 24, 2004 An Update cmd needs a Where clause, in a sense you need to pin-point the exact record to update, Is this what you are currently doing? If the record already exists, is this not what you want? To update an existing record. When I create the dataset I use a WHERE condition, so the dataset contains only the records I want. After I declare it, I use the following syntax to get the UPDATE command automatically from the DB: DataAdapter.UpdateCommand = CommandBuilder.GetUpdateCommand Then, when I update the dataset into the database, I use: DataAdapter.Update(DataSet, "TableName") What should I do ? Thanks, Tom. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.