Solved

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

Posted on 2011-09-16
9
323 Views
Last Modified: 2012-05-12
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
Comment
Question by:Ammar Iqbal
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 16

Accepted Solution

by:
disrupt earned 167 total points
ID: 36549588
0
 
LVL 1

Author Comment

by:Ammar Iqbal
ID: 36549601
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
 
LVL 16

Expert Comment

by:disrupt
ID: 36549602
in the copy you can delete the first row as so:

http://msdn.microsoft.com/en-us/library/feh3ed13(v=VS.100).aspx
0
Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

 
LVL 16

Expert Comment

by:disrupt
ID: 36549632
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
 
LVL 1

Author Comment

by:Ammar Iqbal
ID: 36549637
i am using .NET framework 2.0, and linq is not included in it
0
 
LVL 16

Expert Comment

by:disrupt
ID: 36549665
you should be able to still remove the first row...using the other example...
0
 
LVL 16

Expert Comment

by:disrupt
ID: 36549666
0
 
LVL 15

Assisted Solution

by:x77
x77 earned 166 total points
ID: 36549813
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
 

Assisted Solution

by:soniczoo
soniczoo earned 167 total points
ID: 36552371

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

Featured Post

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question