473,396 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to copy datarow from one datatable to another ?

can anyone tell me please ..

how to copy one datarow from one datatable to another..

I want to extract some specific rows from one datatable and put into antoher
....

" datatableOne.rows.add(datatableTwo.rows(i))"

this statement does not work ..it says

"This row already belongs to another table"
what is the solution please ...
Nov 18 '05 #1
3 9421
CT
Try this:
http://support.microsoft.com/default...;EN-US;Q308909

--
Carsten Thomsen
Enterprise Development with VS .NET, UML, and MSF
http://www.apress.com/book/bookDisplay.html?bID=105
"ypul" <yp**@hotmail.com> wrote in message
news:OQ**************@TK2MSFTNGP12.phx.gbl...
can anyone tell me please ..

how to copy one datarow from one datatable to another..

I want to extract some specific rows from one datatable and put into
antoher
...

" datatableOne.rows.add(datatableTwo.rows(i))"

this statement does not work ..it says

"This row already belongs to another table"
what is the solution please ...

Nov 18 '05 #2
Hi,
i am not sure if we can add a row which is a part of another table. I have
written a sample to explain how to do that.
DataTable myTableOne = new DataTable("firstTable");
myTableOne.Columns.Add("fCol1");
for(int i = 0; i<5;i++)
{
DataRow myDr = myTableOne.NewRow();
myDr[0] = i.ToString();

myTableOne.Rows.Add(myDr);
myDr = null;
}

DataTable myTableTwo = new DataTable("secondTable");
myTableTwo.Columns.Add("fCol1");
for(int i=0;i<myTableOne.Rows.Count;i++)
{
DataRow tempRow = myTableTwo.NewRow();
// you can loop here for each columns in the tableone if
you have more columns
tempRow[0] = myTableOne.Rows[i][0];

// tempRow = myTableOne.Rows[i];
// Remember will not work here as its the refrence
// of the row from tableone which is assigned to the
temprow so temprow will be pointing to
// the row of tabletwo

myTableTwo.Rows.Add(tempRow);
tempRow = null;
}

HTH
Regards
Ashish M Bhonkiya

"ypul" <yp**@hotmail.com> wrote in message
news:OQ**************@TK2MSFTNGP12.phx.gbl...
can anyone tell me please ..

how to copy one datarow from one datatable to another..

I want to extract some specific rows from one datatable and put into antoher ...

" datatableOne.rows.add(datatableTwo.rows(i))"

this statement does not work ..it says

"This row already belongs to another table"
what is the solution please ...

Nov 18 '05 #3
I did it myself in a different manner

dtfinal.Rows.Add(dt.Rows(introws).ItemArray)

thanks all
"Ashish M Bhonkiya" <bh******@hotmail.com.nospam> wrote in message
news:eE**************@TK2MSFTNGP09.phx.gbl...
Hi,
i am not sure if we can add a row which is a part of another table. I have written a sample to explain how to do that.
DataTable myTableOne = new DataTable("firstTable");
myTableOne.Columns.Add("fCol1");
for(int i = 0; i<5;i++)
{
DataRow myDr = myTableOne.NewRow();
myDr[0] = i.ToString();

myTableOne.Rows.Add(myDr);
myDr = null;
}

DataTable myTableTwo = new DataTable("secondTable");
myTableTwo.Columns.Add("fCol1");
for(int i=0;i<myTableOne.Rows.Count;i++)
{
DataRow tempRow = myTableTwo.NewRow();
// you can loop here for each columns in the tableone if
you have more columns
tempRow[0] = myTableOne.Rows[i][0];

// tempRow = myTableOne.Rows[i];
// Remember will not work here as its the refrence
// of the row from tableone which is assigned to the
temprow so temprow will be pointing to
// the row of tabletwo

myTableTwo.Rows.Add(tempRow);
tempRow = null;
}

HTH
Regards
Ashish M Bhonkiya

"ypul" <yp**@hotmail.com> wrote in message
news:OQ**************@TK2MSFTNGP12.phx.gbl...
can anyone tell me please ..

how to copy one datarow from one datatable to another..

I want to extract some specific rows from one datatable and put into

antoher
...

" datatableOne.rows.add(datatableTwo.rows(i))"

this statement does not work ..it says

"This row already belongs to another table"
what is the solution please ...


Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Kelvin | last post by:
Hi All, Due to can't insert new row between row and row while current DataTable looping. In order to solve the problem, I need to clone it as new DataTable, while the DataTable Looping, it also...
0
by: Bennett Haselton | last post by:
If I have just filled a DataTable in a typed DataSet with a single row, is there a way I can make a copy of that row, so that I can clear the DataTable in that DataSet and use it for another query,...
3
by: Shawn | last post by:
Hi. I have 2 DataTables, dataTable1 and dataTable2. dataTable1 contains a DataRow that I need to insert at index 5 in dataTable2. Here is my code: For Each dataRow1 In dataTable1.Rows If...
2
by: Li Pang | last post by:
Hi, I created a datatable (dt1) of 3 columns A, B, C, and I want to copy this datatable into another datatable (dt2) but without the column B. How to do this? Thanks in advance
6
by: JIM.H. | last post by:
Hello I have; DataRow dr= dataSet11.myTable.NewRow(); And I am filling the fields of this datarow. Now I need to create a copy of this row as drCopy and change a few fields and add both to...
1
by: Mo | last post by:
Hi, I have two datasets on two databases one remote and one local. I am trying to copy the local data into the remote. Both tables have the same structure. I use the following DataTable...
5
by: samoore33 | last post by:
I use the code below to return rows matching the state in the theState variable. I want to know if it is possible to search through the DataRow that I am returning with the search. I understand...
6
by: Pete Wittig | last post by:
Hi, I have a DataTable and I want to get a subset of the rows within it. I use the Select method to get my subset and the results are in a DataRow. I want to put those Rows back into a...
1
by: SunshineInTheRain | last post by:
Dim dtUn As DataTable dtUn= New DataTable dtUn = BindICUN() Dim i As Integer Dim irow As DataRow Dim mailBody As String = "" Dim myRow As...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.