How to add rows of one DataTable into another?

Posted by Webmaster under ASP.NET on 4/30/2007 | Views : 23600 | Status : [Administrator] | Replies : 5
Hi,

I want to know how to add rows of one datatable into another. What is the easiest way to do it?

Thanks

Best regards,
Webmaster
http://www.dotnetfunda.com



Responses

Posted by: Sabarimahesh on: 4/3/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi
http://www.justskins.com/forums/copying-datarows-to-another-148799.html

Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

Webmaster, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Yadav.Ashwani on: 6/18/2012 [Member] Starter | Points: 25

Up
0
Down
we can add row of one DT to another DataTable

DataTable first=new DataTable();

DataRow Frow=dt.Rows[1]; //any row

DataTable second=first.Clone(); // its must to get schema info of first table

foreach(DataRow r in Frow) // use for multiple row
{
second.ImportRow(r);

}


Then display second table or Bind to Data Access control

Webmaster, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Learningtorise on: 7/25/2013 [Member] Starter | Points: 25

Up
0
Down
Can't we just finish it in one statement???

like
datatable1 = datatable2;



Newa eva had tried above statement myself though ! I'm just curious...

http://hashtagakash.wordpress.com/

Webmaster, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Webmaster on: 6/7/2007 [Administrator] HonoraryPlatinum

Up
0
Down
I think this is the simplest way to do it.



Dim dataTableFiltered as new DataTable
dataTableFiltered = dataTableToCopy.Clone()
Dim dRow As DataRow

For Each row As DataRow In m_DataTable.Rows
dRow = dataTableFiltered.NewRow()
dRow.ItemArray = row .ItemArray
dataTableFiltered.Rows.Add(dRow)
Next




Best regards,
Webmaster
http://www.dotnetfunda.com

Webmaster, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vsnmurthy.vepa on: 9/3/2007 [Member] Starter

Up
0
Down
datatable.row.import will help try it

Webmaster, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response