Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old August 14th, 2003, 12:33 PM
Friend of Wrox
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default DataTable belongs to another DataSet


I'm trying to pass a DataTable back from a function, and would like to incorporate it into another DataSet. This is my function:

Function GetData(...) as DataTable

    objAdapter.Fill(objDataSet, "Data")
    return objDataSet.Tables("Data")
End Function
I want to insert the table into a new dataset back in the caller (because I got to call 4 GetData() methods in different classes). I am having problems, because I can't use the notation
because it says the table belongs to another dataset. So I changed it to do
, but the Clone() method only clones the structure, so I lose the data, and you can't clone each row separately...

Any ideas?


Brian Mains
Old September 20th, 2003, 10:51 AM
Registered User
Join Date: Sep 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts

Use Copy. It copies both the schema and the data.

Old December 20th, 2005, 12:24 AM
Registered User
Join Date: Dec 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to dwhite

Sorry for the resurrection, but found a far better solution, this doesn't have the overhead that a copy does. Copy would be a nightmare if this general function was used reasonably often.

Function GetData(...) as DataTable

    objAdapter.Fill(objDataSet, "Data")

    Dim tmpTable As DataTable
    ' Remembering that the assignment operator doesn't copy the whole object, just a reference to the object.
    tmpTable = objDataSet.Tables("Data")

    ' or: objDataSet.Tables.Remove(tmpTable.TableName)

    return tmpTable
End Function
The beauty of the first way is that you don't even need to know which DataSet the table belongs to.

Similar Threads
Thread Thread Starter Forum Replies Last Post
Rearrange the column order in a datatable/dataset kiran_q8 ASP.NET 2.0 Professional 2 May 3rd, 2007 08:46 AM
Creating DataSet/DataTable from XML hhmoeller XML 4 March 22nd, 2006 10:41 AM
For Loop problem with DataSet\DataTable musa BOOK: ASP.NET Website Programming Problem-Design-Solution 2 December 25th, 2003 03:11 AM
For Loop problem with DataSet\DataTable musa BOOK: Professional C#, 2nd and 3rd Editions 1 December 24th, 2003 09:46 AM
For Loop problem with DataSet\DataTable musa BOOK: Beginning ASP.NET 1.0 0 December 23rd, 2003 06:31 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.