if result = system.dbnull

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • cj

    if result = system.dbnull

    in the command window I get:

    ? result
    {System.DBNull}
    [System.DBNull]: {System.DBNull}

    I need to check for this in code. I then tested in the command window

    if result = system.DBNull
    'DBNull' is a type and cannot be used as an expression.

    How can I check to see if result is equal system.dbnull in my code?
  • Marina Levit [MVP]

    #2
    Re: if result = system.dbnull

    Either of the following:

    If IsDBNull(result ) Then...
    If result = DBNull.Value Then...

    "cj" <cj@nospam.nosp am> wrote in message
    news:OaXJp1qRGH A.4688@TK2MSFTN GP11.phx.gbl...[color=blue]
    > in the command window I get:
    >
    > ? result
    > {System.DBNull}
    > [System.DBNull]: {System.DBNull}
    >
    > I need to check for this in code. I then tested in the command window
    >
    > if result = system.DBNull
    > 'DBNull' is a type and cannot be used as an expression.
    >
    > How can I check to see if result is equal system.dbnull in my code?[/color]


    Comment

    • pvdg42

      #3
      Re: if result = system.dbnull


      "cj" <cj@nospam.nosp am> wrote in message
      news:OaXJp1qRGH A.4688@TK2MSFTN GP11.phx.gbl...[color=blue]
      > in the command window I get:
      >
      > ? result
      > {System.DBNull}
      > [System.DBNull]: {System.DBNull}
      >
      > I need to check for this in code. I then tested in the command window
      >
      > if result = system.DBNull
      > 'DBNull' is a type and cannot be used as an expression.
      >
      > How can I check to see if result is equal system.dbnull in my code?[/color]

      Perhaps this will help:

      Visual Basic (Declaration)
      Public Shared Function IsDBNull ( _
      value As Object _
      ) As Boolean

      Visual Basic (Usage)
      Dim value As Object
      Dim returnValue As Boolean

      returnValue = Convert.IsDBNul l(value)


      --
      Peter [MVP Visual Developer]
      Jack of all trades, master of none.


      Comment

      • cj

        #4
        Re: if result = system.dbnull

        Thanks. I'll go with IsDBNull(result )

        Marina Levit [MVP] wrote:[color=blue]
        > Either of the following:
        >
        > If IsDBNull(result ) Then...
        > If result = DBNull.Value Then...
        >
        > "cj" <cj@nospam.nosp am> wrote in message
        > news:OaXJp1qRGH A.4688@TK2MSFTN GP11.phx.gbl...[color=green]
        >> in the command window I get:
        >>
        >> ? result
        >> {System.DBNull}
        >> [System.DBNull]: {System.DBNull}
        >>
        >> I need to check for this in code. I then tested in the command window
        >>
        >> if result = system.DBNull
        >> 'DBNull' is a type and cannot be used as an expression.
        >>
        >> How can I check to see if result is equal system.dbnull in my code?[/color]
        >
        >[/color]

        Comment

        • cj

          #5
          Re: if result = system.dbnull

          I think I sww where you're going with this but I've already changed it
          to one of Marina Levit's ideas.

          Also I'm not sure how all this would fit in with, result is declared as
          an object. My intention was to declare result as a string but it turns
          out when there is nothing to put in it instead of it getting a null
          string it gets dbnull. arrrrgh! So now result is a object and I can
          check to see if it's dbnull if not it's a string. Seems to work. So
          perhaps I can finish this darn program now.


          pvdg42 wrote:[color=blue]
          > "cj" <cj@nospam.nosp am> wrote in message
          > news:OaXJp1qRGH A.4688@TK2MSFTN GP11.phx.gbl...[color=green]
          >> in the command window I get:
          >>
          >> ? result
          >> {System.DBNull}
          >> [System.DBNull]: {System.DBNull}
          >>
          >> I need to check for this in code. I then tested in the command window
          >>
          >> if result = system.DBNull
          >> 'DBNull' is a type and cannot be used as an expression.
          >>
          >> How can I check to see if result is equal system.dbnull in my code?[/color]
          >
          > Perhaps this will help:
          >
          > Visual Basic (Declaration)
          > Public Shared Function IsDBNull ( _
          > value As Object _
          > ) As Boolean
          >
          > Visual Basic (Usage)
          > Dim value As Object
          > Dim returnValue As Boolean
          >
          > returnValue = Convert.IsDBNul l(value)
          >
          >[/color]

          Comment

          • Armin Zingler

            #6
            Re: if result = system.dbnull

            "cj" <cj@nospam.nosp am> schrieb[color=blue]
            > in the command window I get:
            >
            > ? result
            > {System.DBNull}
            > [System.DBNull]: {System.DBNull}
            >
            > I need to check for this in code. I then tested in the command
            > window
            >
            > if result = system.DBNull
            > 'DBNull' is a type and cannot be used as an expression.
            >
            > How can I check to see if result is equal system.dbnull in my code?[/color]

            If result is DBnull.value then



            Armin

            Comment

            • Herfried K. Wagner [MVP]

              #7
              Re: if result = system.dbnull

              "cj" <cj@nospam.nosp am> schrieb:[color=blue]
              > How can I check to see if result is equal system.dbnull in my code?[/color]

              'If x Is DBNull.Value Then...' or 'If IsDBNull(x) Then...'.

              --
              M S Herfried K. Wagner
              M V P <URL:http://dotnet.mvps.org/>
              V B <URL:http://classicvb.org/petition/>

              Comment

              Working...