Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 333
  • 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 IqbalAuthor 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 IqbalAuthor 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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