Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / May 2005

Tip: Looking for answers? Try searching our database.

Cloning Row in Typed Dataset Table

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
wacampbell - 20 May 2005 20:50 GMT
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?
MajorTom - 20 May 2005 22:45 GMT
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

>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?
wacampbell - 21 May 2005 01:27 GMT
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
MajorTom - 21 May 2005 14:53 GMT
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

> Thanks for the reply MajorTom,
>
[quoted text clipped - 31 lines]
>
> Wayne
darek - 21 May 2005 20:04 GMT
[...]
> 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);

Signature

darek


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.