Hi,
I'm having some troubles using Session Variables as they are being used as Reference and I want to use them as value.
I got to this debuging my solution and I created something like:
DataTable dt =
(DataTable)HttpContext.Current.Session[
"SearchReturn-DataTableSchema"];
// Adding Rows of Data to DataTable dt
HttpContext.Current.Session["SearchReturn-DataTable"] = dt;
((DataTable)HttpContext.Current.Session[
"SearchReturn-DataTableSchema"]).Rows.Clear();
return dt;
my idea was to have in "DataTableSchema" only the DataTable with the Columns Schema and in "DataTable" the Columns + Rows.
Problem is that when I clear all rows from DataTableSchema, the variable dt will have the Rows cleared as well (!!)
How can avoid this? How can assign a variable (in this case a Session variable) as a value and not as a reference?
Thank you.
Answer
this
DataTable dt = (DataTable)Session["SearchReturn-DataTableSchema"];
needs to be this:
DataTable dt = ((DataTable)Session["SearchReturn-DataTableSchema"]).Copy();
:-)