Re: Merge is adding 2 records to the dataset

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: news.microsoft.com (v-hshah_at_microsoft.com)
Date: 02/23/05


Date: Wed, 23 Feb 2005 05:26:38 -0500

What if i'm doing only 1 record update at a time.

Also my insert command also has a select statement which uses the @@Identity
to get the auto # assigned to the new row.

Are you saying I update the "dsOriginal" from "dsGetchanges" and then merge?

Then why merge at all ?

Do you have a code snippet I can use ? or any article/book you can point me
to.

Thanks.

HS
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
news:%23GtH%23IYGFHA.1084@tk2msftngp13.phx.gbl...
> Hi Hemang,
>
> Yes, this is how Merge works - it looks at primary key to find out whether
> row exists or not and it is not very Update friendly.
> In autoinc case it thinks that there is a new row since the primary keys
> differ.
> This is how I solve it:
> Before doing update I link same rows from original and getchanges dataset
> (I create an array of instances of a class that holds references to both
> rows)
> After update I manually refresh the primary key of original rows from the
> updated rows (first setting DataColumn.ReadOnly = false, refresh the value
> and reset ReadOnly).
> And then, I do the merge.
>
> --
> Miha Markic [MVP C#] - RightHand .NET consulting & development
> www.rthand.com
> SLODUG - Slovene Developer Users Group www.codezone-si.info
>
> "Hemang Shah" <hemang@hemang.net> wrote in message
> news:e_SdnRDyw-vYMobfRVn-jg@rogers.com...
>> What im doing:
>>
>> Adding new record to my form.
>>
>> Creating a temp dataset "dsChanges" by using getchanges()
>>
>> dataadapter.update(dsChanges)
>>
>> Then I merge my original dataset dsOriginal.merge(dsChanges)
>>
>> But now my dataset has 2 records instead of 1,
>>
>> one with the auto id field = -1 and one with the autoid field as the one
>> retrived from the database.
>>
>> The database has only 1 record added though.(which is correct).
>>
>> Anyone got any inputs on this one ?
>>
>> Thanks
>>
>>
>
>



Relevant Pages

  • RE: Adding new row to datagrid
    ... Note:- if there is primary key in the table and u are accessing that primary ... automatically generate the updtae insert and delete command. ... the new row data to the database? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Altering Table - Adding Primary Key With References
    ... In identity relashionship primary key from parent table migrate in child ... In ALTER TABLE command works similarly. ... > Relations between tables can be defined in the database but they are not ...
    (microsoft.public.fox.vfp.dbc)
  • RE: How do I automatically open a form linked to the current record?
    ... as long as the table has a primary key and you haven't dirtied ... See http://www.QBuilt.com for all your database needs. ... See http://www.Access.QBuilt.com for Microsoft Access tips. ... I need to create a command button that would pull up a form ...
    (microsoft.public.access.modulesdaovba)
  • Re: Merge is adding 2 records to the dataset
    ... this is how Merge works - it looks at primary key to find out whether ... Before doing update I link same rows from original and getchanges dataset (I ... After update I manually refresh the primary key of original rows from the ... > The database has only 1 record added though.. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Losing patience with .NET... one thing after another... .Update Method..
    ... Don't forget to send the database you are using. ... > The farm_trans table has a primary key.. ... > be included in the INSERT command during the RowUpdating event... ... >> Graham, ...
    (microsoft.public.dotnet.languages.vb)