Web design and development with excellence

How To Copy DataRow From One Table To Another In ASP .Net

By manik26 • Aug 14th, 2009 • Category: Blog

How do you copy the DataRow of one DataTable to another DataTable?

Lets say you have a source DataTable dt. This is how you copy the rows from dt to a new DataTable.

DataTable dtDest = new DataTable();
DataSet dsSource = new DataSet();
dsSource.Tables.Add(dt);
dtDest =dsSource.Tables[0].Clone();
foreach (DataRow dr in dataTable.Rows)
{
DataRow newRow = dtDest.NewRow();
newRow.ItemArray = dr.ItemArray;
dtDest.Rows.Add(newRow);
}