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 can i check linq query return with value or not ??

how can i check linq query return with value or not ??

Scheduled Pinned Locked Moved LINQ
questioncsharpdatabaselinq
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.
  • A Offline
    A Offline
    ahmedhassan96
    wrote on last edited by
    #1

    hi every body i want know the way which i can check the query result and is it has value or not ex: i made this query var res = from x in rs.Users where x.UserName == "name" select x; i want check if res has value or not thanx for ur time

    P J 2 Replies Last reply
    0
    • A ahmedhassan96

      hi every body i want know the way which i can check the query result and is it has value or not ex: i made this query var res = from x in rs.Users where x.UserName == "name" select x; i want check if res has value or not thanx for ur time

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      bool hasValue = res.Count > 0;

      Deja View - the feeling that you've seen this post before.

      My blog | My articles | MoXAML PowerToys

      1 Reply Last reply
      0
      • A ahmedhassan96

        hi every body i want know the way which i can check the query result and is it has value or not ex: i made this query var res = from x in rs.Users where x.UserName == "name" select x; i want check if res has value or not thanx for ur time

        J Offline
        J Offline
        J4amieC
        wrote on last edited by
        #3

        var res = (from x in rs.Users
        where x.UserName == "name"
        select x).FirstOrDefault();

        if res == null after that then no record was returtned, otherwise res will have the value of x. You may also like to lookup SingleOrDefault() which is similar.

        N 1 Reply Last reply
        0
        • J J4amieC

          var res = (from x in rs.Users
          where x.UserName == "name"
          select x).FirstOrDefault();

          if res == null after that then no record was returtned, otherwise res will have the value of x. You may also like to lookup SingleOrDefault() which is similar.

          N Offline
          N Offline
          Nilish
          wrote on last edited by
          #4

          Sorry for interrupting in ur thread , actually my question is little similar to ur’s After finding that the result is nothing /or not nothing, I have to insert the ---Select--- record in the combobox , at first place.how can it append to combobox.

          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