Re: Cloning A DataRow

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



Scott,

Whatever you copy, then it is always a shalow copy of the copied one.

By instance this code (version 2008 type VB)

\\\
Dim scottsSet As New Scott
Dim scottsTable = scottsSet.DataTable1
Dim firstRow = scottsTable.NewDataTable1Row
firstRow.DataColumn1 = "One"
firstRow.DataColumn2 = "two"
scottsTable.AddDataTable1Row(firstRow)

Dim corsSet As New Scott
corsSet.Merge(scottsTable)
///

Here the scottsSet and the corsSet are in fact completely the same and reference to the same data. (a change in the corsSet is in fact the same as in the scottsSet).

This is because you are in fact only working with references. To add values to the datarows you have really to set the items to values.

I assume you knew this already however wanted it to be showed by somebody else.

Cor



"Scott M." <smar@xxxxxxxxxxxxx> schreef in bericht news:Oz3s%23KthIHA.2304@xxxxxxxxxxxxxxxxxxxxxxx
Hi Cor,

As I said the row I want to copy will be placed into another typed-dataset of the same type, so there will be no issuse with column mapping.

-Scott

"Cor Ligthert[MVP]" <notmyfirstname@xxxxxxxxx> wrote in message news:1CF300D0-058C-444E-9765-FC87CEB00C6E@xxxxxxxxxxxxxxxx
Scott,

It depends if it is for the same datatable or that you want to put it in an other datatable.

As you know is the datarow using the columns descriptions from the datatable, that is the reason that you never can copy whatever datarow to another table. (The datarow has even one property table, which tells to what tables it belongs (get its columns from)).

Be aware that with strongly typed datasets the merge is an important method, while it is in my idea with non typed ones mostly ignored.

Cor

"Scott M." <smar@xxxxxxxxxxxxx> schreef in bericht news:uttKc9rhIHA.5824@xxxxxxxxxxxxxxxxxxxxxxx
I need to copy an entire row of a typed DataSet so that I can place it into a different instance of the same type of typed DataSet. I don't see a clone or copy method on the DataRow. Do I have to create and populate the row manually?

-Scott





.



Relevant Pages

  • Re: Cloning A DataRow
    ... Then you have to copy the values and not the references in that. ... I want to make a copy of the DataRow object (and thus the data in the ... Dim scottsSet As New Scott ... Be aware that with strongly typed datasets the merge is an important ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Cloning A DataRow
    ... You can simple do that by using a for each loop through the DataColumns, the only problem is that you can use the datacolumn from the references table and have for the other one the DataColumn.Name. ... I want to make a copy of the DataRow object, so that the copy can exist in a separate DataTable than the first one. ... Dim scottsSet As New Scott ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Cloning A DataRow
    ... DataRow), so that the copy can exist in a separate DataTable than the first ... Dim scottsSet As New Scott ... Dim corsSet As New Scott ... Be aware that with strongly typed datasets the merge is an important ...
    (microsoft.public.dotnet.framework.adonet)