Solved

Copy DataRows between in-memory Datasets

Posted on 2011-09-22
2
275 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
[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
  • 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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.
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 …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

705 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