Help with DBNUll

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

    #1

    Help with DBNUll

    Hello:

    When I try to do the following,
    Dim liTemp As System.DBNull
    If c.Value Is Nothing Then
    newDataTableRow (c.Column.Key) = liTemp
    Else
    newDataTableRow (c.Column.Key) = c.Value
    End If
    I get the exception:

    Exception Details: System.Argument Exception: Cannot set Column 'D_STAT_DT'
    to be null. Please use DBNull instead.

    Am I not doing that?

    Venki

  • W.G. Ryan - MVP

    #2
    Re: Help with DBNUll

    Try using DbNull.Value
    "vvenk" <vvenk@discussi ons.microsoft.c om> wrote in message
    news:C30CEA14-F37A-423F-B79D-163B59E01CA0@mi crosoft.com...[color=blue]
    > Hello:
    >
    > When I try to do the following,
    > Dim liTemp As System.DBNull
    > If c.Value Is Nothing Then
    > newDataTableRow (c.Column.Key) = liTemp
    > Else
    > newDataTableRow (c.Column.Key) = c.Value
    > End If
    > I get the exception:
    >
    > Exception Details: System.Argument Exception: Cannot set Column 'D_STAT_DT'
    > to be null. Please use DBNull instead.
    >
    > Am I not doing that?
    >
    > Venki
    >[/color]


    Comment

    • Bart Mermuys

      #3
      Re: Help with DBNUll

      Hi,

      "vvenk" <vvenk@discussi ons.microsoft.c om> wrote in message
      news:C30CEA14-F37A-423F-B79D-163B59E01CA0@mi crosoft.com...[color=blue]
      > Hello:
      >
      > When I try to do the following,
      > Dim liTemp As System.DBNull
      > If c.Value Is Nothing Then
      > newDataTableRow (c.Column.Key) = liTemp
      > Else
      > newDataTableRow (c.Column.Key) = c.Value
      > End If
      > I get the exception:[/color]

      Try using DBNull.Value, eg:

      If c.Value Is Nothing Then
      newDataTableRow (c.Column.Key) = DBNull.Value
      Else
      newDataTableRow (c.Column.Key) = c.Value
      End If

      hth,
      Greetings
      [color=blue]
      >
      > Exception Details: System.Argument Exception: Cannot set Column 'D_STAT_DT'
      > to be null. Please use DBNull instead.
      >
      > Am I not doing that?
      >
      > Venki
      >[/color]


      Comment

      • Herfried K. Wagner [MVP]

        #4
        Re: Help with DBNUll

        "vvenk" <vvenk@discussi ons.microsoft.c om> schrieb:[color=blue]
        > When I try to do the following,
        > Dim liTemp As System.DBNull
        > If c.Value Is Nothing Then
        > newDataTableRow (c.Column.Key) = liTemp[/color]

        Replace the line above with '...(...) = DBNull.Value'. 'DBNull' is a type
        and thus cannot be assigned to the variable.
        [color=blue]
        > Else
        > newDataTableRow (c.Column.Key) = c.Value
        > End If
        > I get the exception:
        >
        > Exception Details: System.Argument Exception: Cannot set Column 'D_STAT_DT'
        > to be null. Please use DBNull instead.[/color]

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

        Comment

        • Cor Ligthert [MVP]

          #5
          Re: Help with DBNUll

          VVenk,

          You have not instanced your[color=blue]
          > Dim liTemp As System.DBNull[/color]

          Probably
          Dim liTemp As System.DbNull = Nothing

          Will give you the result you want.

          However I use direct dbnull.Value

          I hope this helps,

          Cor


          Comment

          • Herfried K. Wagner [MVP]

            #6
            Re: Help with DBNUll

            Cor,

            "Cor Ligthert [MVP]" <notmyfirstname @planet.nl> schrieb:[color=blue]
            > You have not instanced your[color=green]
            >> Dim liTemp As System.DBNull[/color]
            >
            > Probably
            > Dim liTemp As System.DbNull = Nothing[/color]

            I assume you wanted to write '... As DBNull = DBNull.Value'.

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

            Comment

            • Cor Ligthert [MVP]

              #7
              Re: Help with DBNUll

              Herfried,

              I saw everybody giving the same answers as Bill did.

              Therefore I thought I do the same, however you know if I do that, it has to
              be an addition or something else.

              I was thinking on your option, however the one I gave did look for me even
              more different.

              Therefore I tested it before and had the idea that it was working.

              :-)

              Cor


              Comment

              Working...