PC Review


Reply
Thread Tools Rate Thread

DataRow primary key is not updated although the DataSet's PK is

 
 
=?Utf-8?B?Y2hqb3NzaUBnbXguY2g=?=
Guest
Posts: n/a
 
      29th Jun 2005
Hi Guys

I created a DataRow, that automatically sets its primary key. Let us say 3.

I then added the DataRow to the DataSet and then update the DataSet using
GetChanges() and finally Merge().

The primary key in the Microsoft SQL DB is set to 23 and consequently the PK
in the dataset's row is also set to 23.

What confuses me is that my originally created DataRow does still contain
the old PK value and therefore gives me some troubles.

I thought, that a the DataRow is passed as reference object and should
therefore be the same as the row in the dataset.

Is there any possibility to update this datarow without just getting the
last row from the updated dataset.

Appended the code that I use: ( the dataTable contains two columns, the PK
which is indexed and the name)

DataRow dr = myDataSet.MyTable.NewRow();
dr["Name"] = "Chris"; [dr["ID"] is set to 3!!!]
myDataSet.MyTable.Add(dr);
DataSet changedRecords = myDataSet.GetChanges();
myDataAdapter.Update(changedRecords);
myDataSet.Merge(changedRecords);
myDataSet.AcceptChanges(); [I am not sure if it needs this!]

myDataSet.MyTable.Rows[0]["ID"] is now 23!!!
dr["ID"] is still 3!!!!

Thanks for your help
Chris
 
Reply With Quote
 
 
 
 
=?Utf-8?B?U2hhaSBHb2xkYmVyZw==?=
Guest
Posts: n/a
 
      29th Jun 2005
try setting the UpdatedRowSource property of the SelectCommand (or maybe the
UpdateCommand) of the DataAdapter to have the value of UpdateRowSource.Both,
I think this will force the update in the DataRow


--
If I helped you please Press Yes
Shai


"(E-Mail Removed)" wrote:

> Hi Guys
>
> I created a DataRow, that automatically sets its primary key. Let us say 3.
>
> I then added the DataRow to the DataSet and then update the DataSet using
> GetChanges() and finally Merge().
>
> The primary key in the Microsoft SQL DB is set to 23 and consequently the PK
> in the dataset's row is also set to 23.
>
> What confuses me is that my originally created DataRow does still contain
> the old PK value and therefore gives me some troubles.
>
> I thought, that a the DataRow is passed as reference object and should
> therefore be the same as the row in the dataset.
>
> Is there any possibility to update this datarow without just getting the
> last row from the updated dataset.
>
> Appended the code that I use: ( the dataTable contains two columns, the PK
> which is indexed and the name)
>
> DataRow dr = myDataSet.MyTable.NewRow();
> dr["Name"] = "Chris"; [dr["ID"] is set to 3!!!]
> myDataSet.MyTable.Add(dr);
> DataSet changedRecords = myDataSet.GetChanges();
> myDataAdapter.Update(changedRecords);
> myDataSet.Merge(changedRecords);
> myDataSet.AcceptChanges(); [I am not sure if it needs this!]
>
> myDataSet.MyTable.Rows[0]["ID"] is now 23!!!
> dr["ID"] is still 3!!!!
>
> Thanks for your help
> Chris

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting a datarow from a dataset! DBC User Microsoft C# .NET 3 14th Jul 2006 08:14 PM
Dataset doesn't return true when dataset datarow has been modified =?Utf-8?B?QWxwaGE=?= Microsoft C# .NET 3 11th Nov 2005 09:16 PM
Retrieving Original Values From Updated DataRow? Axel Dahmen Microsoft ADO .NET 3 5th Aug 2005 10:04 AM
DataSet and DataRow Question Yosh Microsoft C# .NET 1 15th Jun 2005 12:38 AM
DataSet and DataRow Question Yosh Microsoft Dot NET 1 14th Jun 2005 08:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:54 AM.