Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Value versus Reference
Message
From
13/09/2010 15:57:04
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 3.0
Miscellaneous
Thread ID:
01481001
Message ID:
01481035
Views:
30
>>Hi,
>>
>>If I want to store a value retrieved for later and it is a reference type value, how can I convert this to a value? Here is what I mean.
>>
>>
>>DataSet dsSmith = this.oContact.GetContactByLastName("Smith");
>>Session["dsSmith"] = dsSmith
>>
>>DataSet dsMiller = this.oContact.GetContactByLastName("Miller");
>>Session["dsMiller"] = dsMiller;
>>
>>// Get the dataset back from the session
>>DataSet dsGetSmith = (DataSet)Session["dsSmith"];
>>
>>DataSet dsGetMiller = (DataSet)Session["dsMiller"];
>>
>>// Both dsGetSmith & dsGetMiller have the exact same dataset.
>>
>>
>>When the first dataset is retrieved and saved in the session the value is as expected. When the second dataset is retrieved the first dataset that was saved is replaced because it was a reference. How can I copy a dataset to a value so it does not get a reference update?
>>Thanks
>>Tim
>
>I think there is CopyDS or something like this, although I'm not sure I understand how did you end up with the same dataset.


This is quite interesting actually. Apparently when you save something to a Session variable, it obviously has to hold a real copy as the reference goes away after the page events are all finished and done and everything is gone. But the values must not be saved in the session until a later event. Maybe the Page_SaveStateComplete or something. I will later experiment and see if I can figure that out.
Tim
Timothy Bryan
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform