473,789 Members | 3,157 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.ro ws.add(datatabl eTwo.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 9449
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.c om> wrote in message
news:OQ******** ******@TK2MSFTN GP12.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.ro ws.add(datatabl eTwo.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("firs tTable");
myTableOne.Colu mns.Add("fCol1" );
for(int i = 0; i<5;i++)
{
DataRow myDr = myTableOne.NewR ow();
myDr[0] = i.ToString();

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

DataTable myTableTwo = new DataTable("seco ndTable");
myTableTwo.Colu mns.Add("fCol1" );
for(int i=0;i<myTableOn e.Rows.Count;i+ +)
{
DataRow tempRow = myTableTwo.NewR ow();
// 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.c om> wrote in message
news:OQ******** ******@TK2MSFTN GP12.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.ro ws.add(datatabl eTwo.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.Ad d(dt.Rows(intro ws).ItemArray)

thanks all
"Ashish M Bhonkiya" <bh******@hotma il.com.nospam> wrote in message
news:eE******** ******@TK2MSFTN GP09.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("firs tTable");
myTableOne.Colu mns.Add("fCol1" );
for(int i = 0; i<5;i++)
{
DataRow myDr = myTableOne.NewR ow();
myDr[0] = i.ToString();

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

DataTable myTableTwo = new DataTable("seco ndTable");
myTableTwo.Colu mns.Add("fCol1" );
for(int i=0;i<myTableOn e.Rows.Count;i+ +)
{
DataRow tempRow = myTableTwo.NewR ow();
// 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.c om> wrote in message
news:OQ******** ******@TK2MSFTN GP12.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.ro ws.add(datatabl eTwo.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
5832
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 insert both of new row and existing datarow into new DataTable, but I don't know how to do that, Here is my souce code, Please advise. if ( myTable.Rows.Count > 0 )
0
1242
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, but my copy of the row will be preserved? If I try to do something like this: this.oleDbWbuserAdapter.SelectCommand.CommandText = "SELECT * FROM wbuser where username='bennett';"; this.oleDbWbuserAdapter.Fill(ds1.wbuser);
3
11456
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 dataRow1.Item("id") = "3353" Then dataRow2 = dataRow1 End If Next
2
1732
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
1639
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 the dataset, how can I do this? Thanks,
1
4058
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 Remote_Table = new DataTable(); Remote_Table = dsRemote.Tables.Clone(); DataRow DR_Local = dsLocal.Tables.Select(); foreach(DataRow Local_Data in(DR_Local))
5
8363
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 that that creates a DataRow Array. I searched through group postings and found where Cor had said something about bulding the DataTable back, not sure what that meant of if I could use it with this, but any help would be appreciated. Dim t As...
6
28330
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 DataTable. I've tried a few variations of the following but no rows are every imported into the datatable: DataRow datrow = ds.Tables.Select("PersonID = " + id); DataTable dt = new DataTable();
1
1507
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 DataRow Dim rowSet As DataRow() rowSet = dtUn.Select("Distinct Member_id is not null")
0
9511
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10408
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10139
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9983
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9020
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6768
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5417
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.