C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » ADO.NET »

Copy DataRow from one table to another table


Posted Date: 16 Sep 2009    Resource Type: Code Snippets    Category: ADO.NET
Author: hiteshMember Level: Gold    
Rating: 1 out of 5Points: 6



Copy DataRow from one table to another table



Assuming a following datatable with 3 columns named 'Title', 'Author', 'Price'

Method [a]

DataTable dt = new DataTable("Book");
...
..
// create a new row
DataRow dr = dt.NewRow();

// This will copy the 3rd row into new DataRow object 'dr'
dr.ItemArray = dt.Rows[2].ItemArray;


Method [b] - Brute force

DataTable dt = new DataTable("Book");
...
..

// This will copy the 3rd row into new DataRow object 'dr'
DataRow dr = dt.NewRow();
for (int j = 0; j < dt.Columns.Count; j++)
{
dr[j] = dt.Rows[2][j];
}


I have not shown the complete code about table initialization, however it's easy to understand the logic from above example.



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Table  .  Datarow copy to another table  .  DataRow  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Storing values in a Oracle Database
Previous Resource: Read Data From Excel sheet using Excel.Application Object
Return to Discussion Resource Index
Post New Resource
Category: ADO.NET


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use