int session variable

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,
int myID=(int)Session["myID"];
this gives invalid cast.
myID is a int value and I kept it as a session variable and trying to read
it as int again. Can I keep int as a session variable?
Thanks,
Jim.
 
Hi Jim,

yes, you can keep int (and all other types) as Session. You need to check if
it is set to a reference, before you cast it.

int myID = -1;
if (Session ["myID"] != null)
myID = (int)Session ["myID"]);

If this does not work, you REALLY does not have a integer value in the
session-variable.

cu patrick
 
Hi Jim,
Try this..
Convert.ToInt16(Session["myID"].ToString())
or
Convert.ToInt16(Session["myID"])

HTH,

Happy Coding
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top