Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - table into another dataset

 
Thread Tools Search this Thread
Old 12-30-2003, 12:44 AM   #1
Default table into another dataset


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
  Reply With Quote
Old 12-30-2003, 01:51 AM   #2
chanmm
 
Posts: n/a
Default Re: table into another dataset
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
  Reply With Quote
Old 12-30-2003, 02:38 AM   #3
Ken Cox [Microsoft MVP]
 
Posts: n/a
Default Re: table into another dataset
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]
  Reply With Quote
Old 12-30-2003, 04:07 AM   #4
Steven Cheng[MSFT]
 
Posts: n/a
Default RE: table into another dataset
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]
  Reply With Quote
Old 12-30-2003, 04:15 PM   #5
Marty McDonald
 
Posts: n/a
Default Re: table into another dataset
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
  Reply With Quote
Old 12-30-2003, 04:16 PM   #6
Marty McDonald
 
Posts: n/a
Default Re: table into another dataset
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
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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

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




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46