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 get value

How to get value

Scheduled Pinned Locked Moved LINQ
csharpdatabasequestionlinqsales
3 Posts 2 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
    Steve van Niman
    wrote on last edited by
    #1

    New to Linq and C# so go easy please. How do I get the value from a query. I understand it returns a result set, but I just want to put a value into a local variable. var customer = from c in db.Customers where c.cid = 1 select c.CustomerName; string sCustomerName = ?; Thanks!

    A 1 Reply Last reply
    0
    • S Steve van Niman

      New to Linq and C# so go easy please. How do I get the value from a query. I understand it returns a result set, but I just want to put a value into a local variable. var customer = from c in db.Customers where c.cid = 1 select c.CustomerName; string sCustomerName = ?; Thanks!

      A Offline
      A Offline
      Arun Jacob
      wrote on last edited by
      #2

      try this, string customer = (from c in db.Customers where c.cid = 1 select c.CustomerName).FirstOrDefault(); assuming that cid is the unique. :)

      Arun Jacob http://codepronet.blogspot.com/

      S 1 Reply Last reply
      0
      • A Arun Jacob

        try this, string customer = (from c in db.Customers where c.cid = 1 select c.CustomerName).FirstOrDefault(); assuming that cid is the unique. :)

        Arun Jacob http://codepronet.blogspot.com/

        S Offline
        S Offline
        Steve van Niman
        wrote on last edited by
        #3

        Arun, Many Thanks! Did the trick. There are some great videos on the ASP.NET site and they were very helpful for getting started, just didn't address pulling specific values from the result set... Regards, Steve

        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