Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

C# - Add/Copy Rows from One Datatable to Another Datatable

Aug 29, 2013
Introduction:

Here I will explain simple
code snippet in c# to add rows from one table to another table in vb.net, asp.net or copy rows from one datatable to another datatable in  c#, vb.net.

Description:

In Previous posts I explained using statement example in c#, Get all files from folder and subfolders in c#, Export webpage with images to pdf in asp.net and many articles relating to
c#, vb.net, Asp.net, Gridview, SQL Server, Ajax, JavaScript etc. Now I will explain how to add rows from one table to another table in c#, vb.net, asp.net.  

To add rows from one table to another table we need to use ImportRow function like as shown below

C# Code


DataTable _dt=new DataTable();
_dt = _ds.Tables[0];
DataTable dt1 = ds1.Tables[0];
for (int i = 0; i < dt1.Rows.Count; i++)
{
_dt.ImportRow(dt1.Rows[i]);
}
VB.NET Code


Dim _dt As New DataTable()
_dt = _ds.Tables(0)
Dim dt1 As DataTable = ds1.Tables(0)
For i As Integer = 0 To dt1.Rows.Count - 1
_dt.ImportRow(dt1.Rows(i))
Next

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

0 comments :

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.