Here is the sample code for copying DataRow from one DataTable to another DataTable in ADO.NET 2.0.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
public DataTable CopyDataTable(DataTable OldTable)
{
    DataTable NewTable = new DataTable();
    DataRow NewRow = null;
 
    try
    {
        NewTable = OldTable.Clone();
        foreach(DataRow OldRow in OldTable.Rows)
        {
              NewRow = NewTable.NewRow();
              NewRow.ItemArray = OldRow.ItemArray;
              NewTable.Rows.Add(NewRow);
        }
     }
     catch (Exception) { throw; }
 
     return NewTable;
}

 

Comments