Click here to Skip to main content
15,890,609 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hai all,when i write below

int id = Convert.ToInt16(System.Web.HttpContext.Current.Session.SessionID);

it shows no error and int the time of exicution it says input string is not correct formate

what is the error in the above line...??and why IDE did't allow me to write like

int id = Convert.Int16(System.Web.HttpContext.Current.Session.SessionID);

please help me..

Thanks and Regards
Posted
Comments
Richard C Bishop 24-Oct-13 15:38pm    
Debug it and see what value you are getting as the SessionID, if it contains letters and numbers, the conversion won't work.
adityaimmadi 24-Oct-13 15:41pm    
yes sir,it contains some random numbers and letters.what can i do now ,why this happens..
can you please tell me the solution...
Thanks in advance
Richard C Bishop 24-Oct-13 15:45pm    
If you just need the SessionID, assign it to a string value instead of an int. try this:

string id = (System.Web.HttpContext.Current.Session.SessionID).ToString();
adityaimmadi 24-Oct-13 15:52pm    
sir,i already tried it before posting the question
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);---at this line i got error in converting nvachar value to it int.thats why i changed above line
DataList1.DataSource = ds;
DataList1.DataBind();
Richard C Bishop 24-Oct-13 15:58pm    
Let me see your sql statement.

1 solution

Hello,

You take the problem the wrong way round. You wont be able to use a integer.

SessionID is a string not an integer, so it's likely that it wont convert to an integer.
See here: http://msdn.microsoft.com/en-us/library/system.web.sessionstate.httpsessionstate.sessionid(v=vs.110).aspx[^]

What you can do is:
C#
string id = System.Web.HttpContext.Current.Session.SessionID;


Valery.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900