• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 335
  • Last Modified:

How to copy from one datable to another in Vb.net

I need to copy one datatable (dt) to another datatble (dt2), dataset or Data view in VB.NET.
  and I want to skip first  first row  in dt, and copy rest of the rows in dt2.
0
Ammar Iqbal
Asked:
Ammar Iqbal
3 Solutions
 
Ammar IqbalSenior IT Consultant/senior Software engineerAuthor Commented:
This thing I know, but i do not want to copy all data. I need to skip first row  , and copy rest of the rows
0
 
disruptCommented:
in the copy you can delete the first row as so:

http://msdn.microsoft.com/en-us/library/feh3ed13(v=VS.100).aspx
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
disruptCommented:
You can either delete the first row using example above  or use LINQ to manipulate the data in the datatable as so:

http://dotnetarchitect.wordpress.com/2009/03/18/using-linq-to-manipulate-data-in-datasetdatatable/
0
 
Ammar IqbalSenior IT Consultant/senior Software engineerAuthor Commented:
i am using .NET framework 2.0, and linq is not included in it
0
 
disruptCommented:
you should be able to still remove the first row...using the other example...
0
 
x77Commented:
Use ImportRow For each Row you can copy:

    Dim Rows = T1.Select
    For N = 1 To Rows.Length - 1
        t2.ImportRow(Rows(N))
    Next

This copy not deleted rows (T1.Select), skiping First row.

Note that you can Filter or Sort using Select.
Note that this method also copy RowState (DataRowVersion.Current and DataRowVersion.Original)
0
 
soniczooCommented:

Dim dt2 As DataTable = dt.Clone()
dt2.Rows.RemoveAt(0)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now