devxlogo

A Quick Way to Copy DataRow

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.

See also  Why ChatGPT Is So Important Today
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist