Home > C# Programming Tips > Copy One DataRow From A DataTable to Another DataTable

Copy One DataRow From A DataTable to Another DataTable

every C# programmer deals with populating, selecting, and even deleting from a DataTable. A moderately advanced operation is transferring an entire single row from an original DataTable and inserting it into a new DataTable

DataTable originalTable=new DataTable();

/*Add datas to this data table*/

DataTable newTable = originalTable.Clone(); //make new table with same structre of OriginalTable

DataRow newRow = newTable.NewRow();

newRow.ItemArray = originalTable.Rows[1].ItemArray; //Copy Row at index 1..If we need to copy morethan 1 row loop this section

newTable.Rows.Add(newRow); //add this row to the new data table

Advertisements
Categories: C# Programming Tips
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: