Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. How to pass querytring value in LINQ

How to pass querytring value in LINQ

Scheduled Pinned Locked Moved LINQ
csharpdatabaselinqtutorial
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sarang_k
    wrote on last edited by
    #1

    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.

    A M U 3 Replies Last reply
    0
    • S sarang_k

      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.

      A Offline
      A Offline
      Abhishek Sur
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • S sarang_k

        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.

        M Offline
        M Offline
        MohitBhambral
        wrote on last edited by
        #3

        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; }

        1 Reply Last reply
        0
        • S sarang_k

          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.

          U Offline
          U Offline
          Umar F Khawaja
          wrote on last edited by
          #4

          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?

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups