Guru E. Technology

need of every business.


How to Copy Entire DataTable Row to Another DataTable?

Whenever we do play with the DataSet or DataTable.  We always need solution to copy entire row from one table to another table. It’s very easy in another way by creating new object of data table and set each column value from another row column.

I wondered if both objects (data rows) have same set of columns then why I can’t copy directly from the row like dataRowNew = dataRowOld. So following is the solution for this query:

DataRow dr;
dr = newDataTable.NewRow(); //assuming that you have created the table with the columns.
dr.ItemArray = oldDataRow.ItemArray;
newDataTable.Rows.Add(dr);

Just these 3 lines will copy entire cells data to another row cells and add to the table.

Posted in ASP.Net, Developer Solutions


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>