Click here to Skip to main content
15,918,343 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using entity framework problem in getting data in session.
C#
var res = from a in ef.Logins where a.username == txtuser.Text && a.password == txtpass.Text select a.login_id;
Session["rcode"]=res;

if(Session["rcode"]!=null)
{
Abc obj=(Abc)Session["rcode"];
lable.text=obj.loginid;/// con not show data in lable
}

Error message is:
C#
System.Data.Objects.ObjectQuery`1[System.String]
Posted
Updated 12-Dec-13 9:35am
v2
Comments
[no name] 12-Dec-13 3:46am    
from where your exception occured ? Please mention.
if it is from lable.text=obj.loginid; line,
then call obj.loginid.toString();
JoCodes 12-Dec-13 23:59pm    
In which line exactly the error occurred?. I dont think its related to your session storage rather its related to your linq query.

Try something like
var res = from a in ef.Logins where a.username == txtuser.Text && a.password == txtpass.Text select a.login_id;
string loginID= res.SingleOrDefault();
//expecting a.login_id is string Datatype.

Then assign the value to Session and access accordingly.

Hope this helps you
 
Share this answer
 
have you tried this
Session["rcode"]=res.ToString();
 
Share this answer
 
See we can modify it in different ways
IF you need login id then by the data type "select a.login_id"
XML
<pre lang="cs">
int res =Convert.ToInt32( from a in ef.Logins where a.username == txtuser.Text && a.password == txtpass.Text select a.login_id);
Session["rcode"]=res;

if(Session[&quot;rcode&quot;]!=null)
{ 
lable.text=Session["rcode"].ToString(); 
}</pre>


Then If you need to keep whole login class in Session
Code below
Login res = (from a in ef.Logins where a.username == txtuser.Text && a.password == txtpass.Text select a).FirstOrDefault();
Session["rcode"]=res;
 
if(Session["rcode"]!=null)
{
Login obj=(Login )Session["rcode"];
lable.text=obj.loginid;/// con not show data in lable
}
 
Share this answer
 
Comments
awaisshabir 19-Dec-13 6:24am    
solution 2 is correct
[no name] 19-Dec-13 6:44am    
It's good, If it really helped you put a mark as answer

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



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