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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dataset as a session variable

Status
Not open for further replies.

JenJen

Programmer
Joined
Sep 24, 2002
Messages
10
Location
GB
Hi, I hope someone can help.
I am using a session variable to store a dataset as -

Session.Add("dsCustRecord", dsSearchResults);

I know that dsSearchResults is a dataset which contains 1 row.
When I later use the session variable -

DataSet dsCustRecord = new DataSet();
dsCustRecord = (DataSet)Session["dsCustRecord"];

The row has disappeared but the table is still there.

Where have I gone wrong?

Many Thanks.
 
Are you sure the record is added correctly to the DataSet and is subsequently saved in the session variable? i.e. just doing a simple test:

1) if you write out the rows of the table before you add it to the session variable, does the row exist?
2) As soon as you have written it to the session (not later on in code but straight after adding it), does the row exist?




____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Thanks for the response. I have written out the row before and after creating the session variable and it is there. It seems to get lost once I have called other pages.
 
That would seem to suggest that either it is:

1) Being overwritten elsewhere
2) Dropping the session

I think number 2 can be ruled out if you say that the table still exists, so I would look into the possibility of number 1.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
The table does still exists as I am binding it to a datagrid which shows the column headings. I have checked and the sessions variable is never overwritten, only ever accessed. It is an odd one.
 
I have tested this some more, and there is definitely one row in the dataset. If I fill it with more records, then the session variable works. It only seems to fail when there is only 1 row in it.
 
can you post your code for when you use it and there's only 1 record in it?

"...we both know I'm training to become a cagefighter...see what happens if you try 'n hit me..."
 
DataSet dsSearchResults = oDatabaseSearch.DataSearch("Search", htReturnFields, "Customer", aCriteriaFields);
Session.Add("dsCustRecord", dsSearchResults);
string sCustName = "";
string sLogo = "";
string sImage = "";
string sButtonType = "";
foreach (DataTable oTable in dsSearchResults.Tables)
{
foreach (DataRow oRow in oTable.Rows)
{
sCustName = oRow["sCompanyName"].ToString();
sLogo = oRow["sLogo"].ToString();
sImage = oRow["sImage"].ToString();
sButtonType = oRow["sButtonType"].ToString();
}
}
Session.Add("sCustName", sCustName);
Session.Add("sLogo", sLogo);
Session.Add("sCustImage", sImage);
Session.Add("sButtonType", sButtonType);

The session variables which I set within the loop, I can access fine.
 
If you can, don't store such large amounts of data in a session - it could become a huge overhead!
 
so this code retrieving the records fine? where are you adding the records?

"...we both know I'm training to become a cagefighter...see what happens if you try 'n hit me..."
 
I am adding the records from a class I have written which is all working correctly as I am getting the correct customer name etc returned. I can use this from the Session CustName.
Just to give you a little more info, I am creating these session variables in global.asax.cs. For testing purposes I added a loop in here after I have created the session variable which is a dataset, and this loop returns one record. So I know the dataset has one record in at this point. The first page which loads is default.asax which has a datagrid on it. I am just trying to databind the dataset from the session variable to the datagrid. It adds the table correctly, so the headers are there but no row.
If I return more records 2+, the rows are added correctly. Only seems to fail when the dataset only has one row in it.
 
Which I know sounds completely illogical.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top