How can we copy datacolumn with data from one table to another ?
Posted
by Harikrishna
on Stack Overflow
See other posts from Stack Overflow
or by Harikrishna
Published on 2010-04-06T06:23:48Z
Indexed on
2010/04/06
8:53 UTC
Read the original article
Hit count: 255
I have one Datatable like
DataTable addressAndPhones;
And there are four columns name,address,phoneno,and other details and I only want two columns Name and address from that so I do for that is
DataTable addressAndPhones2;
addressAndPhones2.Columns.Add(new DataColumn(addressAndPhones.Columns["name"].ColumnName));
addressAndPhones2.Columns.Add(new DataColumn(addressAndPhones.Columns["address"].ColumnName));
But it gives me error so how can I copy fix no of columns data from one table to another table ?
ERROR :Object reference not set to an instance of an object.
EDIT : Only column is copied to another table, data of that column is not copied to another table.
© Stack Overflow or respective owner