Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

  • Moderators
Posted

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.

Visit...Bassic Software
Posted
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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...