![]() |
|
|
|
#1 |
|
I execute a method that returns a dataset, but I want the table in another
dataset. Clone won't work because it does not include data. Can I somehow use the existing table in another dataset without getting the "table already belongs to another dataset" error? Thanks! --Marty Marty McDonald |
|
|
|
|
#2 |
|
Posts: n/a
|
Can you do something like:
ds.Tables.Add(das1.Tables(0)) "Marty McDonald" <> wrote in message news:... > I execute a method that returns a dataset, but I want the table in another > dataset. Clone won't work because it does not include data. Can I somehow > use the existing table in another dataset without getting the "table already > belongs to another dataset" error? Thanks! > --Marty > > chanmm |
|
|
|
#3 |
|
Posts: n/a
|
Hi Marty,
Are you able to use Copy? Maybe I've misunderstood your issue, but this seems to work for me: Private Sub Page_Load _ (ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles MyBase.Load Dim ds As New DataSet Dim ds2 As New DataSet Dim dt As New DataTable Dim dtsrc As New datasrc dt = dtsrc.CreateDataSource() ds.Tables.Add(dt) ds2.Tables.Add(dt.Copy) DataGrid1.DataSource = ds2 DataGrid1.DataBind() End Sub "Marty McDonald" <> wrote in message news:... >I execute a method that returns a dataset, but I want the table in another > dataset. Clone won't work because it does not include data. Can I somehow > use the existing table in another dataset without getting the "table > already > belongs to another dataset" error? Thanks! > --Marty > > Ken Cox [Microsoft MVP] |
|
|
|
#4 |
|
Posts: n/a
|
Hi Marty McDonald,
Thanks for using Microsoft NewsGroup Services. Based on your description, you want to copy a DataTable in one DataSet into another DataSet( not only the structure but also with the datas) so as to do some operations on the new copied DataTable. Is my understanding of your problem correct? If so, I think Ken Cox's suggestion is good, you may try the DataTable's copy method which will generate a same DataTAble as the origianl one with not only structure but datas as well. Such as : [Visual Basic] Private Sub CopyDataTable(ByVal myDataTable As DataTable ) ' Create an object variable for the copy. Dim copyDataTable As DataTable copyDataTable = myDataTable.Copy() ' Insert code to work with the copy. End Sub [C#] private void CopyDataTable(DataTable myDataTable){ // Create an object variable for the copy. DataTable copyDataTable; copyDataTable = myDataTable.Copy(); // Insert code to work with the copy. } Please try out the suggestion. If you have any question on it ,please feel free to let me know. Steven Cheng Microsoft Online Support Get Secure! www.microsoft.com/security (This posting is provided "AS IS", with no warranties, and confers no rights.) Steven Cheng[MSFT] |
|
|
|
#5 |
|
Posts: n/a
|
Yes Steven, you are correct, I want the table (structure & data) from one
dataset copied into another dataset. You and Ken are correct, the Copy method solves the problem. I just did not look closely enough at the available methods, thank you for the information! --Marty Marty McDonald |
|
|
|
#6 |
|
Posts: n/a
|
That causes the error about the table already belonging to another dataset.
We did find the correct answer though, it is posted in this thread. Thanks for your help! "chanmm" <> wrote in message news:... > Can you do something like: > ds.Tables.Add(das1.Tables(0)) > > "Marty McDonald" <> wrote in message > news:... > > I execute a method that returns a dataset, but I want the table in another > > dataset. Clone won't work because it does not include data. Can I somehow > > use the existing table in another dataset without getting the "table > already > > belongs to another dataset" error? Thanks! > > --Marty > > > > > > Marty McDonald |
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| changing Crystal report table at run time | rakesh201180 | Software | 1 | 10-22-2008 10:58 AM |
| large dataset to xml in vb.net | vbcheerful | Software | 0 | 04-09-2008 03:33 AM |
| High-Def Playback: The Firmware Gotcha | Ablang | DVD Video | 46 | 07-28-2007 07:25 AM |
| Uploading Excel file into sql table | shalim | Software | 1 | 10-31-2006 08:57 AM |
| How to store dataset to a table in the database. Please be specific. Urgent | fullblown | General Help Related Topics | 0 | 09-20-2006 03:55 PM |