Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I want a copy of an object not a reference to 2

Status
Not open for further replies.

Deleco

Programmer
Feb 25, 2002
109
0
0
GB
Hi,

I have the following code

Code:
        Dim dsShoppingBasket As DataSet
        Dim dtDelegates As DataTable
        Dim dsCompiled As New DataSet
        Dim dtShoppingBasket As New DataTable

        dsShoppingBasket = Session("dsShoppingBasket")
        dtDelegates = Session("dtDelegates")

        dtShoppingBasket = dsShoppingBasket.Tables(0)
        dsShoppingBasket.Tables.Remove(dsShoppingBasket.Tables(0))

        dsCompiled.Tables.Add(dtShoppingBasket)
        dsCompiled.Tables.Add(dtDelegates)

I am forced to remove the table from the dsShoppingBasket dataset as i am adding it too the dsCompiled dataset. Because i remove this table it also removes it from the DataSet stored in the session variable which i use else where. Does anyone know any way that i can add a copy of the table to the dsCompiled dataset rather than adding the reference to the table in the dsShoppingBasket Dataset.

Any help would be appreciated :)

Deleco
 
Try

Dim objTable As DataTable
Dim obJTable2 As DataTable
obJTable2 = objTable.Clone()
 
That copies the Table structure but not the data. Is there any way to keep the data???

Deleco
 
this worked for me...
Code:
Dim dt As DataTable = dr.returnDataTable(myC, "k")
Dim da As DataTable = dt.Copy
Response.Write(dt.Rows.Count)
Response.Write(da.Rows.Count)

"...we both know I'm training to become a cagefighter...see what happens if you try 'n hit me..."
 
Take a look at Clone() and the ICloneable interface. No idea if the DataTable supports it, but that's generally how the framework does it.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Thanks Chiph!

That worked great :)

Deleco
 
so what was the solution that you used?

"...we both know I'm training to become a cagefighter...see what happens if you try 'n hit me..."
 
Sorry checkai. thanked the wrong person. Your the genius ;) Your solution worked a treat...

Deleco
 
Deleco -
Go ahead and redflag my response, then. Tell site management you gave me the star by mistake.

Sorry it didn't (really) work for you.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top