Hello... I need some help/advice regarding using a dataset in session state.
When a request first comes to my ASP.NET application, I have code in the Session_Start event to query the user table, which return a dataset. I then add this dataset to a Session variable.
This works, but my questions are:
1. Is storing a dataset in session state the best approach to handle my situation? Or, is there some better alternative? Note that the queried results are user-specific, so application cache wouldn't work.
2. Assuming I go forward with the dataset in session state idea, how do I access an individual element in the data table in the data set that's in the session state variable?
I have this code:
System.Data.DataSet ds = (System.Data.DataSet) Session["reportLogonUser"];
But, then what?
Thanks.
For 1, it is a common approach.
For2, now that you have the dataset, you can iterate it for your results. You can think of the datatable as a grid matrix which allows direct access like so
string str = ds.Tables[0].Rows[2][3].ToString();
or if you don't know exactly where it is, you can iterate the datatable or use the find function of the datatable which is optimized for lookups and guaranteed to be faster than iteration since it is based on indices/indexes.

Signature
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/27cok
Hello... I need some help/advice regarding using a dataset in session state.
When a request first comes to my ASP.NET application, I have code in the Session_Start event to query the user table, which return a dataset. I then add this dataset to a Session variable.
This works, but my questions are:
1. Is storing a dataset in session state the best approach to handle my situation? Or, is there some better alternative? Note that the queried results are user-specific, so application cache wouldn't work.
2. Assuming I go forward with the dataset in session state idea, how do I access an individual element in the data table in the data set that's in the session state variable?
I have this code:
System.Data.DataSet ds = (System.Data.DataSet) Session["reportLogonUser"];
But, then what?
Thanks.