Click here to Skip to main content
15,896,912 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I am using linq-to-sql to connect my web application to sql server... my code is.

EmployeeCheckoutDataContext db = new EmployeeCheckoutDataContext();
EmployeeDetail ed = null;
C#
protected void Button1_Click(object sender, EventArgs e)
{
    ed = (from a in db.GetTable<EmployeeDetail>()
          where (a.Name == "xyz")
                select a).SingleOrDefault<EmployeeDetail>();
    Label1.Text = ed.EmployeeNo;
}


as i compile the code, the error i get is "Specified cast is not valid." at code
SQL
ed = (from a in db.GetTable&lt;EmployeeDetail&gt;()
         where (a.Name == &quot;xyz&quot;)
               select a).SingleOrDefault&lt;EmployeeDetail&gt;();

i had also tried with var type. i am completely blank to how this is happening.. any help??
Posted

1 solution

i updated datacontext and now its working...
 
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
Top Experts
Last 24hrsThis month


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