PC Review


Reply
Thread Tools Rate Thread

Cloning Row in Typed Dataset Table

 
 
=?Utf-8?B?d2FjYW1wYmVsbA==?=
Guest
Posts: n/a
 
      20th May 2005
I am having touble figuring out a good way to clone a record ( row ) in a
typed dataset table without copying each field one by one. Is there a
'clone' function that I have missed that would allow me to make a deep copy
of a record?
 
Reply With Quote
 
 
 
 
MajorTom
Guest
Posts: n/a
 
      20th May 2005
uhmm ?



YourTypeDataSetClass.tablenameRow yourNewRecorsRow;



mow you can use it



yourNewRecorsRow =
(YourTypeDataSetClass.tablenameRow)YourTypedDataset.table[pos];



the are many ways to do this, the better approach depend on you particular
code.



I hope I understand you question



MajorTom



"wacampbell" <(E-Mail Removed)> wrote in message
news:180D0B8C-A2A5-47D8-86DE-(E-Mail Removed)...
>I am having touble figuring out a good way to clone a record ( row ) in a
> typed dataset table without copying each field one by one. Is there a
> 'clone' function that I have missed that would allow me to make a deep
> copy
> of a record?



 
Reply With Quote
 
=?Utf-8?B?d2FjYW1wYmVsbA==?=
Guest
Posts: n/a
 
      21st May 2005
Thanks for the reply MajorTom,

I may not have explained it well, and BTW I should have meantioned I am
using C#.

> YourTypeDataSetClass.tablenameRow yourNewRecorsRow;
> yourNewRecorsRow =
> (YourTypeDataSetClass.tablenameRow)YourTypedDataset.table[pos];


I think this just gives me a reference pointer to the record in the dataset.
It doesn't actually copy the record. IE, if I make changes to
'yourNewRecorsRow', it will change the record in the dataset also.

I need to make what I think is called a 'deep copy' so I can change
'yourNewRecorsRow' without affecting the original data in the dataset.

For now, I have been doing this:

YourTypeDataSetClass.tablenameRow yourNewRecorsRow =
(YourTypeDataSetClass.tablenameRow) YourTypeDataSet.tablename.NewRow();

yourNewRecorsRow.Field1 = YourTypeDataSet.tablename[pos].Field1
yourNewRecorsRow.Field2 = YourTypeDataSet.tablename[pos].Field2
..... etc

With the problem being that if I add a field to the dataset, I have to keep
these 'cloning' routines in sync. There has to be some kind of 'deep' record
copy ability somewhere.

Thanks for answering.

Wayne
 
Reply With Quote
 
MajorTom
Guest
Posts: n/a
 
      21st May 2005
if you create a new instance of your dataset and merge to this one your
record is going to be 'disconnected' from the original table.



but you have to use the merge method instead of the copy to avoid the
exception that this record belong to another table.



I going to find an example for you is that approach you think will work, the
big difference is you have a second dataset only for one record.


MajorTom

"wacampbell" <(E-Mail Removed)> wrote in message
news:80C37172-DEE0-4AFB-98AB-(E-Mail Removed)...
> Thanks for the reply MajorTom,
>
> I may not have explained it well, and BTW I should have meantioned I am
> using C#.
>
>> YourTypeDataSetClass.tablenameRow yourNewRecorsRow;
>> yourNewRecorsRow =
>> (YourTypeDataSetClass.tablenameRow)YourTypedDataset.table[pos];

>
> I think this just gives me a reference pointer to the record in the
> dataset.
> It doesn't actually copy the record. IE, if I make changes to
> 'yourNewRecorsRow', it will change the record in the dataset also.
>
> I need to make what I think is called a 'deep copy' so I can change
> 'yourNewRecorsRow' without affecting the original data in the dataset.
>
> For now, I have been doing this:
>
> YourTypeDataSetClass.tablenameRow yourNewRecorsRow =
> (YourTypeDataSetClass.tablenameRow) YourTypeDataSet.tablename.NewRow();
>
> yourNewRecorsRow.Field1 = YourTypeDataSet.tablename[pos].Field1
> yourNewRecorsRow.Field2 = YourTypeDataSet.tablename[pos].Field2
> .... etc
>
> With the problem being that if I add a field to the dataset, I have to
> keep
> these 'cloning' routines in sync. There has to be some kind of 'deep'
> record
> copy ability somewhere.
>
> Thanks for answering.
>
> Wayne



 
Reply With Quote
 
darek
Guest
Posts: n/a
 
      21st May 2005
wacampbell wrote:
[...]
> yourNewRecorsRow.Field1 = YourTypeDataSet.tablename[pos].Field1
> yourNewRecorsRow.Field2 = YourTypeDataSet.tablename[pos].Field2
> .... etc
>

I think, this solves your problem:

TypedDataSet.Table1Row row = typedDataSet1.Table1.NewTable1Row();
row.ItemArray = typedDataSet1.Table1.Rows[0].ItemArray;
typedDataSet1.Table1.AddTable1Row(row);

--
darek
 
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
copying a datatable content from an untyped dataset into a table which is inside a typed dataset Nedu N Microsoft Dot NET Framework 3 31st Oct 2003 02:05 PM
copying a datatable content from an untyped dataset into a table which is inside a typed dataset Nedu N Microsoft ADO .NET 2 31st Oct 2003 02:05 PM
copying a datatable content from an untyped dataset into a table which is inside a typed dataset Nedu N Microsoft ASP .NET 2 31st Oct 2003 02:05 PM
Ccopying a datatable content from an untyped dataset into a table which is inside a typed dataset Nedu N Microsoft ASP .NET 2 31st Oct 2003 03:42 AM
Ccopying a datatable content from an untyped dataset into a table which is inside a typed dataset Nedu N Microsoft Dot NET Framework 2 31st Oct 2003 03:39 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:31 AM.