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. C#
  4. Linq Query Limitations, more than one query fails

Linq Query Limitations, more than one query fails

Scheduled Pinned Locked Moved C#
questioncsharpdatabaselinqsales
5 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.
  • U Offline
    U Offline
    User 13592306
    wrote on last edited by
    #1

    Hello: I simply want to write multiple queries to assign information.

                var q =
                    from a1 in dt\_Jobs.AsEnumerable()
                    orderby a1.Field("Customer")
                    select a1.Field("Customer");
                var lstCustomer = q.Distinct().ToList();
                cboCustomer.DataSource = lstCustomer;
    
                q =
                    from a1 in dt\_Jobs.AsEnumerable()
                    orderby a1.Field("City")
                    select a1.Field("City");
                var lstCity = q.Distinct().ToList();
                cboCity.DataSource = lstCity;
    

    The first block works, the second fails. How can I achieve something like this?? Thanks!

    D 1 Reply Last reply
    0
    • U User 13592306

      Hello: I simply want to write multiple queries to assign information.

                  var q =
                      from a1 in dt\_Jobs.AsEnumerable()
                      orderby a1.Field("Customer")
                      select a1.Field("Customer");
                  var lstCustomer = q.Distinct().ToList();
                  cboCustomer.DataSource = lstCustomer;
      
                  q =
                      from a1 in dt\_Jobs.AsEnumerable()
                      orderby a1.Field("City")
                      select a1.Field("City");
                  var lstCity = q.Distinct().ToList();
                  cboCity.DataSource = lstCity;
      

      The first block works, the second fails. How can I achieve something like this?? Thanks!

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      You're going to have to explain what "fails" means. Did it throw an exception? What was the message? Does something not work as expected? How so and under what conditions?

      Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
      Dave Kreskowiak

      U 1 Reply Last reply
      0
      • D Dave Kreskowiak

        You're going to have to explain what "fails" means. Did it throw an exception? What was the message? Does something not work as expected? How so and under what conditions?

        Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
        Dave Kreskowiak

        U Offline
        U Offline
        User 13592306
        wrote on last edited by
        #3

        I am trying to set the datasources for comboboxes. There is a datasource in the first, but not in the second. If I flip them around, I get the opposite effect.

        U 1 Reply Last reply
        0
        • U User 13592306

          I am trying to set the datasources for comboboxes. There is a datasource in the first, but not in the second. If I flip them around, I get the opposite effect.

          U Offline
          U Offline
          User 13592306
          wrote on last edited by
          #4

          Sorry for the confusion, there are errors. Exception thrown: 'System.FormatException' in mscorlib.dll Exception thrown: 'System.NullReferenceException' in ResourcePlanningC2.exe Exception thrown: 'System.InvalidCastException' in mscorlib.dll Exception thrown: 'System.NullReferenceException' in ResourcePlanningC2.exe Exception thrown: 'System.FormatException' in mscorlib.dll Exception thrown: 'System.NullReferenceException' in ResourcePlanningC2.exe Exception thrown: 'System.NullReferenceException' in ResourcePlanningC2.exe Exception thrown: 'System.FormatException' in mscorlib.dll The program '[12772] ResourcePlanningC2.exe' has exited with code -1 (0xffffffff). It must be hanging on some null values. Is there an easy way to handle this?

          U 1 Reply Last reply
          0
          • U User 13592306

            Sorry for the confusion, there are errors. Exception thrown: 'System.FormatException' in mscorlib.dll Exception thrown: 'System.NullReferenceException' in ResourcePlanningC2.exe Exception thrown: 'System.InvalidCastException' in mscorlib.dll Exception thrown: 'System.NullReferenceException' in ResourcePlanningC2.exe Exception thrown: 'System.FormatException' in mscorlib.dll Exception thrown: 'System.NullReferenceException' in ResourcePlanningC2.exe Exception thrown: 'System.NullReferenceException' in ResourcePlanningC2.exe Exception thrown: 'System.FormatException' in mscorlib.dll The program '[12772] ResourcePlanningC2.exe' has exited with code -1 (0xffffffff). It must be hanging on some null values. Is there an easy way to handle this?

            U Offline
            U Offline
            User 13592306
            wrote on last edited by
            #5

            I think I got it, Thanks for the help!

            var q =
            from a1 in dt_Jobs.AsEnumerable()
            orderby a1.Field("City")
            where (a1.Field("City") != null)
            select a1.Field("City");
            var lstCity = q.Distinct().ToList();
            cboCity.DataSource = lstCity;

            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