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. NULL problem

NULL problem

Scheduled Pinned Locked Moved C#
helpquestion
9 Posts 6 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.
  • X Offline
    X Offline
    Xmen Real
    wrote on last edited by
    #1

    hi there, i have a problem that how can check the value of datagridview is null ?? if i write

    if (DataGridView1[5, a].Value.ToString() == null)

    or

    if (DataGridView1[5, a].Value.ToString().Contains (null))

    or

    if (DataGridView1[5, a].Value.Equals(null))

    all gives the same error Object reference not set to an instance of an object. for temporary i did

    string aaa = DataGridView1[5, a].Value + "D";
    if (aaa.Trim )== "D")

    its working but i dont like this way some know any other good and short way ??

    Becoming Programmer...

    M V G V S 5 Replies Last reply
    0
    • X Xmen Real

      hi there, i have a problem that how can check the value of datagridview is null ?? if i write

      if (DataGridView1[5, a].Value.ToString() == null)

      or

      if (DataGridView1[5, a].Value.ToString().Contains (null))

      or

      if (DataGridView1[5, a].Value.Equals(null))

      all gives the same error Object reference not set to an instance of an object. for temporary i did

      string aaa = DataGridView1[5, a].Value + "D";
      if (aaa.Trim )== "D")

      its working but i dont like this way some know any other good and short way ??

      Becoming Programmer...

      M Offline
      M Offline
      Martin 0
      wrote on last edited by
      #2

      Hello, Have you tried: if (DataGridView1[5, a].Value != null) { //Go on }

      All the best, Martin

      X 1 Reply Last reply
      0
      • X Xmen Real

        hi there, i have a problem that how can check the value of datagridview is null ?? if i write

        if (DataGridView1[5, a].Value.ToString() == null)

        or

        if (DataGridView1[5, a].Value.ToString().Contains (null))

        or

        if (DataGridView1[5, a].Value.Equals(null))

        all gives the same error Object reference not set to an instance of an object. for temporary i did

        string aaa = DataGridView1[5, a].Value + "D";
        if (aaa.Trim )== "D")

        its working but i dont like this way some know any other good and short way ??

        Becoming Programmer...

        V Offline
        V Offline
        V 0
        wrote on last edited by
        #3

        Did you try this? DataGridView1[5, a].Value == DBNull.Value

        V. If I don't see you in this world, I'll see you in the next one... And don't be late. (Jimi Hendrix)

        1 Reply Last reply
        0
        • X Xmen Real

          hi there, i have a problem that how can check the value of datagridview is null ?? if i write

          if (DataGridView1[5, a].Value.ToString() == null)

          or

          if (DataGridView1[5, a].Value.ToString().Contains (null))

          or

          if (DataGridView1[5, a].Value.Equals(null))

          all gives the same error Object reference not set to an instance of an object. for temporary i did

          string aaa = DataGridView1[5, a].Value + "D";
          if (aaa.Trim )== "D")

          its working but i dont like this way some know any other good and short way ??

          Becoming Programmer...

          G Offline
          G Offline
          girm
          wrote on last edited by
          #4

          Hi, According to the exception it is quite clear that CLR bumped into a null value while evaluating "DataGridView1[5, a].Value" what means "DataGridView1[5, a].Value.toString()" if "DataGridView1[5, a].Value" is null ?? You might not assume DataGridView1!=null nor a!=null nor DataGridView1[5, a].Value!=null though the following test should solve your problem : if (DataGridView1[5, a]==null or DataGridView1[5, a].Value==null) { /// } Hope it helps

          1 Reply Last reply
          0
          • X Xmen Real

            hi there, i have a problem that how can check the value of datagridview is null ?? if i write

            if (DataGridView1[5, a].Value.ToString() == null)

            or

            if (DataGridView1[5, a].Value.ToString().Contains (null))

            or

            if (DataGridView1[5, a].Value.Equals(null))

            all gives the same error Object reference not set to an instance of an object. for temporary i did

            string aaa = DataGridView1[5, a].Value + "D";
            if (aaa.Trim )== "D")

            its working but i dont like this way some know any other good and short way ??

            Becoming Programmer...

            V Offline
            V Offline
            Vasudevan Deepak Kumar
            wrote on last edited by
            #5

            if (DataGridView1[5, a] == null)

            Vasudevan Deepak Kumar Personal Homepage Tech Gossips

            M 1 Reply Last reply
            0
            • V Vasudevan Deepak Kumar

              if (DataGridView1[5, a] == null)

              Vasudevan Deepak Kumar Personal Homepage Tech Gossips

              M Offline
              M Offline
              Martin 0
              wrote on last edited by
              #6

              Hello,

              Vasudevan Deepak Kumar wrote:

              if (DataGridView1[5, a] == null)

              I guess this will not help, if this is true: for temporary i did string aaa = DataGridView1[5, a].Value + "D"; if (aaa.Trim )== "D") its working but i dont like this way

              All the best, Martin

              1 Reply Last reply
              0
              • M Martin 0

                Hello, Have you tried: if (DataGridView1[5, a].Value != null) { //Go on }

                All the best, Martin

                X Offline
                X Offline
                Xmen Real
                wrote on last edited by
                #7

                damn..!! why i dont think it before anyway thank you guys below and above this post

                Becoming Programmer...

                1 Reply Last reply
                0
                • X Xmen Real

                  hi there, i have a problem that how can check the value of datagridview is null ?? if i write

                  if (DataGridView1[5, a].Value.ToString() == null)

                  or

                  if (DataGridView1[5, a].Value.ToString().Contains (null))

                  or

                  if (DataGridView1[5, a].Value.Equals(null))

                  all gives the same error Object reference not set to an instance of an object. for temporary i did

                  string aaa = DataGridView1[5, a].Value + "D";
                  if (aaa.Trim )== "D")

                  its working but i dont like this way some know any other good and short way ??

                  Becoming Programmer...

                  S Offline
                  S Offline
                  Syed Mujtaba Hassan
                  wrote on last edited by
                  #8

                  I think your grid must be having only 5 records from 0 to 4. So its not geting the 6th record.

                  Mujtaba "If both of us are having one apple each and we exchange it, at the end we both will have one apple each. BUT if both of us are having one idea each and we exchange it, at the end both of us will be having two ideas each."

                  X 1 Reply Last reply
                  0
                  • S Syed Mujtaba Hassan

                    I think your grid must be having only 5 records from 0 to 4. So its not geting the 6th record.

                    Mujtaba "If both of us are having one apple each and we exchange it, at the end we both will have one apple each. BUT if both of us are having one idea each and we exchange it, at the end both of us will be having two ideas each."

                    X Offline
                    X Offline
                    Xmen Real
                    wrote on last edited by
                    #9

                    no buddy you misundertood the question that wasnt the problem, and now problem has been solved...;););)

                    Becoming Programmer...

                    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