Copy only columns from a datatable
Use 'clone' method to create a datatable with same structure
dtCopyColumns= dt.Clone();
This will copy only columns from dt to dtCopyColumns
Copy columns and rows from a datatable
dtCopy = dt.Copy();
This will copy structure as well as data from dt to dtCopy
Copy selected rows from one datatable to another
To get selected rows from one datatable first create the structure, select rows, copy the rows
dtSelectedRows = dt.Clone();
DataRow[] dr1 = dt.Select("Name = '" + name + "'");
// use your criteria to select rows
foreach (DataRow row1 in dr1)
{
dtSelectedRows.ImportRow(row1);
}
0 Comment(s)