Solved

Copy DataRows between in-memory Datasets

Posted on 2011-09-22
2
270 Views
Last Modified: 2012-05-12
HOW TO - Copy DataRows between in-memory Datasets

        Dim dsIN As New Data.DataSet
... more code ...
        objDataAdapter.Fill(dsIN)

ok ... here I have a Dataset with ONE table
Now I want to DUPLICATE THE TABLE, ITS SCHEMA AND CONTENTS to a NEW dataset
I create the new dataset on-the-fly in-memory


        Dim dsCOPY As DataSet = New DataSet()
        dsCopy.Tables.Add(New DataTable("MyCopy"))
        For Each dc As DataColumn In dsIN.Tables(0).Columns
            dsCopy.Tables("MyCopy").Columns.Add(New DataColumn(dc.ColumnName, dc.DataType))
        Next

OK dsCOPY now duplicates the structure of dsIN
How do I copy all the records from dsIN into dsCopy
I thought this would work ... IT DOES NOT


        For Each drIN As DataRow In dsIN.Tables(0).Rows
            dsCopy.Tables(0).Rows.Add(drIN)
        Next

I get an error message on the dsCopy line ... "This row already belongs to another table."

Fred

0
Comment
Question by:volking
  • 2
2 Comments
 
LVL 5

Accepted Solution

by:
volking earned 0 total points
ID: 36582462
Found solution myself  

http://support.microsoft.com/kb/305346

0
 
LVL 5

Author Closing Comment

by:volking
ID: 36582463
Found the solution myself
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now