A Quick Way to Copy DataRow

Instead of copying DataRow column by column, the following code copies data in one line from the source to the destination row:

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

Note: The ImportRow method does the same thing, except that the RowState of source is preserved in the destination, whereas NewRow sets RowState to Added.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: