Solved

Copy DataRows between in-memory Datasets

Posted on 2011-09-22
2
272 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
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!
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

777 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