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. need Null value to sotre in int [modified]

need Null value to sotre in int [modified]

Scheduled Pinned Locked Moved C#
questionhelp
6 Posts 3 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.
  • M Offline
    M Offline
    mutafa81
    wrote on last edited by
    #1

    Hi if no element return from this i need "loct" to be null int? loct = (from s in sdc.Locations where s.Name == listViewEx4.Items[i].SubItems[7].Text select s.Location_ID).SingleOrDefault(); First() return error message Sequence contains no elements SingleOrDefault() return 0 i need null from this sequence how can i do

    modified on Wednesday, November 12, 2008 10:46 AM

    L J 2 Replies Last reply
    0
    • M mutafa81

      Hi if no element return from this i need "loct" to be null int? loct = (from s in sdc.Locations where s.Name == listViewEx4.Items[i].SubItems[7].Text select s.Location_ID).SingleOrDefault(); First() return error message Sequence contains no elements SingleOrDefault() return 0 i need null from this sequence how can i do

      modified on Wednesday, November 12, 2008 10:46 AM

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      mutafa81 wrote:

      how can i do

      no, try to compile this:

      int n = null;

      Now, read the compiler error message and think about your question. Good luck.

      led mike

      J 1 Reply Last reply
      0
      • L led mike

        mutafa81 wrote:

        how can i do

        no, try to compile this:

        int n = null;

        Now, read the compiler error message and think about your question. Good luck.

        led mike

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

        but the OP was using int? rather than int :confused:

        L 1 Reply Last reply
        0
        • M mutafa81

          Hi if no element return from this i need "loct" to be null int? loct = (from s in sdc.Locations where s.Name == listViewEx4.Items[i].SubItems[7].Text select s.Location_ID).SingleOrDefault(); First() return error message Sequence contains no elements SingleOrDefault() return 0 i need null from this sequence how can i do

          modified on Wednesday, November 12, 2008 10:46 AM

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

          Im guessing your field "Location_ID" is an int rather than an int?, in which case the default is 0 which can be assigned to the int? you could try this:

          int temp = (from s in sdc.Locations
          where s.Name == listViewEx4.Items[i].SubItems[7].Text
          select s.Location_ID).SingleOrDefault();

          int? loct = (temp == 0) ? null : temp;

          M 1 Reply Last reply
          0
          • J J4amieC

            but the OP was using int? rather than int :confused:

            L Offline
            L Offline
            led mike
            wrote on last edited by
            #5

            J4amieC wrote:

            but the OP was using int?

            ooops :-O:-\

            led mike

            1 Reply Last reply
            0
            • J J4amieC

              Im guessing your field "Location_ID" is an int rather than an int?, in which case the default is 0 which can be assigned to the int? you could try this:

              int temp = (from s in sdc.Locations
              where s.Name == listViewEx4.Items[i].SubItems[7].Text
              select s.Location_ID).SingleOrDefault();

              int? loct = (temp == 0) ? null : temp;

              M Offline
              M Offline
              mutafa81
              wrote on last edited by
              #6

              Thank you will try

              J4amieC wrote:

              Im guessing your field "Location_ID" is an int rather than an int?, in which case the default is 0 which can be assigned to the int? you could try this: int temp = (from s in sdc.Locationswhere s.Name == listViewEx4.Items[i].SubItems[7].Textselect s.Location_ID).SingleOrDefault();int? loct = (temp == 0) ? null : temp;

              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