How can we copy one datacolumn with data from one datatable to another datatable ? I have datatable like
DataTable datatable1=new DataTable();
and there are four columns in that table but I want only one column.So I am doing like
DataTable datatable2=new DataTable();
addressAndPhones2.Columns.Add(addressAndPhones.Columns[0].ColumnName,addressAndPhones.Columns[0].DataType);
but this just adds the column but I want to copy the data for that column to the datatable2.That is I want to copy the datacolumn with data from one datatable to another datatable.
Two solutions spring to mind:
The second one is simpler to code but will copy unneeded data (which means extra time and memory).
For the first one, IF you have prepared the destiny-datatable AND the columnnames (and types) in source and destiny are the same:
You can use this like:
naming any number of columns.