Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Value versus Reference
Message
De
13/09/2010 16:46:43
 
 
À
13/09/2010 15:57:04
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 3.0
Divers
Thread ID:
01481001
Message ID:
01481044
Vues:
25
>>>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


DataSet.Copy() should do the trick. If you are storing session state InProc, then you are storing a ref to the dataset. If you persist the Session in a state server or SQL Server, the DS is serialized (Changes made to the DS in memory are not reflected to the DS in Session until session is updated). Hope that makes sense.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform