How to pass querytring value in LINQ
-
Hi all, Can any one tell me,how to pass the querystring value to the LINQ. Following id my sample code and ID is the value of the querystring. var emp = from EmployeeD in db.EDetails where EmployeeD.EmployeeID==ID select EmployeeD I am not getting the result,instead if i pass ID as 2222 i am getting the result. Thanks in advance.
-
Hi all, Can any one tell me,how to pass the querystring value to the LINQ. Following id my sample code and ID is the value of the querystring. var emp = from EmployeeD in db.EDetails where EmployeeD.EmployeeID==ID select EmployeeD I am not getting the result,instead if i pass ID as 2222 i am getting the result. Thanks in advance.
The problem with you is I think Querystring returns a string value, you need to Convert to actual type before you use <code>EmployeeD.EmployeeID==ID</code>. Use <code>Convert.ToInt64</code> if this is a long value and then compare.
Abhishek Sur My Latest Articles Working with Excel using MDAC
Basics on LINQ and Lambda Expressions
Create .NET Templates -
Hi all, Can any one tell me,how to pass the querystring value to the LINQ. Following id my sample code and ID is the value of the querystring. var emp = from EmployeeD in db.EDetails where EmployeeD.EmployeeID==ID select EmployeeD I am not getting the result,instead if i pass ID as 2222 i am getting the result. Thanks in advance.
Hi dear Mohit here at your code behind where you this function call you will just pass the query string value at the place of arguments (e.g) employee emp=FunctionName(convert.Toint32(Request.QueryString["Id"])); public EmployeeD FunctionName(int Id) { var emp = from EmployeeD in db.EDetails where EmployeeD.EmployeeID==ID select EmployeeD return EmployeeD; }
-
Hi all, Can any one tell me,how to pass the querystring value to the LINQ. Following id my sample code and ID is the value of the querystring. var emp = from EmployeeD in db.EDetails where EmployeeD.EmployeeID==ID select EmployeeD I am not getting the result,instead if i pass ID as 2222 i am getting the result. Thanks in advance.
The code you've typed looks fine to me. The only thing I can think of is the data-type of the querystring. It seem to me that the data-type of EmployeeID is int, so equating it with a hardcoded 2222 is working fine, though if there was a datatype mismatch, I'd expect the compiler to complain. What happens when you use the querystring instead of the hardcoded value?