Trying to read DataSet that is stored in Session

  • Thread starter Thread starter Guadala Harry
  • Start date Start date
G

Guadala Harry

This has to be easy...

I have a DataSet stored in the Session object. I simply need to read it
later and get the following error:
Cannot implicitly convert type 'object' to 'System.Data.DataSet'

From a code-behind module of an ASPX page, how do I read the contents of a
DataSet that is stored in the Session?

Thanks in advance.
 
Hi,

I assume you are either using C# or VB.NET with the Option Strict On
setting.
In either case, when retieving the DataSet from the session, you will need
to cast the result.

For C#
ds = (DataSet)Session["YourKeyHere"];

For VB.NET (Option Strict On)

ds = CType( Session("YourKeyHere"), DataSet )
or
ds = DirectCast( Session("YourKeyHere"), DataSet )

Hope this helps
 
Never mind - it is easy - provided that ZoneAlarm is not running... I forgot
that when ZoneAlarm is running, every request for a new page results in the
Session getting blown away and re-initialized. My conversion from object to
DataSet failed because the (new) Session didn't have any DataSet to convert.

G
 
Hi, Guadala Harry,

You need to cast the instance to DataSet:

[C#]
DataSet foo = (DataSet)Session["foo"];

[VB.NET]
DataSet foo = CType(Session("foo"), DataSet)

Greetings
Martin
 
Back
Top