Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 14th, 2003, 12:33 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default DataTable belongs to another DataSet

Hello,

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

Code:
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
Code:
objDataSet.Tables.Add(objTable)
because it says the table belongs to another dataset. So I changed it to do
Code:
objDataSet.Tables.Add(objTable.Clone())
, but the Clone() method only clones the structure, so I lose the data, and you can't clone each row separately...

Any ideas?

Thanks,

Brian Mains
__________________
Brian
Reply With Quote
  #2 (permalink)  
Old September 20th, 2003, 10:51 AM
Registered User
 
Join Date: Sep 2003
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
  #3 (permalink)  
Old December 20th, 2005, 12:24 AM
Registered User
 
Join Date: Dec 2005
Location: Brisbane, Queensland, Australia.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to dwhite
Default

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.

Code:
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")

    tmpTable.DataSet.Tables.Remove(tmpTable.TableName)
    ' 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.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 11:53 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.