How to trap DBNull?

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

    How to trap DBNull?

    Hi all,

    I have a date field in a temp table as part of a DataSet. In some records
    the value is DBNull. how can I trap the error with
    if dtTemp("When") = ??? Then.....

    Thanks,

    Claus


  • Lucas Tam

    #2
    Re: How to trap DBNull?

    "cjobes" <cjobes@nova-tech.org> wrote in news:OAvLiZa1EH A.324
    @TK2MSFTNGP10.p hx.gbl:
    [color=blue]
    > Hi all,
    >
    > I have a date field in a temp table as part of a DataSet. In some records
    > the value is DBNull. how can I trap the error with
    > if dtTemp("When") = ??? Then.....[/color]


    If dtTemp("When") is system.dbnull.v alue then
    Msgbox("oops dbnull!")
    end if



    --
    Lucas Tam (REMOVEnntp@rog ers.com)
    Please delete "REMOVE" from the e-mail address when replying.

    Comment

    • cjobes

      #3
      Re: How to trap DBNull?

      Thanks, that worked.

      Now that the project doesn't time out anymore, I found another problem.
      Where the dtTemp("When") column is not DBNull I need to replace the value of
      another column (dtTemp("When2" ) with a value of a specific variable.
      Rows.Add doesn't work (although the books say that if the PK value for the
      record is already there it would replace the data) and there isn't anything
      like "change" or "replace". How can I do this?

      Thanks,

      Claus


      "Lucas Tam" <REMOVEnntp@rog ers.com> wrote in message
      news:Xns95AFC39 7C92C5nntproger scom@140.99.99. 130...[color=blue]
      > "cjobes" <cjobes@nova-tech.org> wrote in news:OAvLiZa1EH A.324
      > @TK2MSFTNGP10.p hx.gbl:
      >[color=green]
      > > Hi all,
      > >
      > > I have a date field in a temp table as part of a DataSet. In some[/color][/color]
      records[color=blue][color=green]
      > > the value is DBNull. how can I trap the error with
      > > if dtTemp("When") = ??? Then.....[/color]
      >
      >
      > If dtTemp("When") is system.dbnull.v alue then
      > Msgbox("oops dbnull!")
      > end if
      >
      >
      >
      > --
      > Lucas Tam (REMOVEnntp@rog ers.com)
      > Please delete "REMOVE" from the e-mail address when replying.
      > http://members.ebay.com/aboutme/coolspot18/[/color]


      Comment

      • bblyth

        #4
        Re: How to trap DBNull?

        You Need to Edit the ItemArray associated with that row.

        Also Rows.Add does work in a round about way

        Dim DT As New Data.DataTable
        Dim DR As Data.DataRow
        DR = DT.NewRow
        DR.ItemArray(0) = "Test"
        DR.ItemArray(1) = "Test2"
        DT.Rows.Add(DR)


        "cjobes" wrote:
        [color=blue]
        > Thanks, that worked.
        >
        > Now that the project doesn't time out anymore, I found another problem.
        > Where the dtTemp("When") column is not DBNull I need to replace the value of
        > another column (dtTemp("When2" ) with a value of a specific variable.
        > Rows.Add doesn't work (although the books say that if the PK value for the
        > record is already there it would replace the data) and there isn't anything
        > like "change" or "replace". How can I do this?
        >
        > Thanks,
        >
        > Claus
        >
        >
        > "Lucas Tam" <REMOVEnntp@rog ers.com> wrote in message
        > news:Xns95AFC39 7C92C5nntproger scom@140.99.99. 130...[color=green]
        > > "cjobes" <cjobes@nova-tech.org> wrote in news:OAvLiZa1EH A.324
        > > @TK2MSFTNGP10.p hx.gbl:
        > >[color=darkred]
        > > > Hi all,
        > > >
        > > > I have a date field in a temp table as part of a DataSet. In some[/color][/color]
        > records[color=green][color=darkred]
        > > > the value is DBNull. how can I trap the error with
        > > > if dtTemp("When") = ??? Then.....[/color]
        > >
        > >
        > > If dtTemp("When") is system.dbnull.v alue then
        > > Msgbox("oops dbnull!")
        > > end if
        > >
        > >
        > >
        > > --
        > > Lucas Tam (REMOVEnntp@rog ers.com)
        > > Please delete "REMOVE" from the e-mail address when replying.
        > > http://members.ebay.com/aboutme/coolspot18/[/color]
        >
        >
        >[/color]

        Comment

        • cjobes

          #5
          Re: How to trap DBNull?

          When I try this I get an error msg that the row already belongs to the
          table. I also to update the item by assigning the new value to
          TableX.ItemArra y(3)="new value"
          One column is configured as PK auto.

          "bblyth" <bblyth@discuss ions.microsoft. com> wrote in message
          news:8D34037B-F85C-425F-A810-DE666A9209AA@mi crosoft.com...[color=blue]
          > You Need to Edit the ItemArray associated with that row.
          >
          > Also Rows.Add does work in a round about way
          >
          > Dim DT As New Data.DataTable
          > Dim DR As Data.DataRow
          > DR = DT.NewRow
          > DR.ItemArray(0) = "Test"
          > DR.ItemArray(1) = "Test2"
          > DT.Rows.Add(DR)
          >
          >
          > "cjobes" wrote:
          >[color=green]
          > > Thanks, that worked.
          > >
          > > Now that the project doesn't time out anymore, I found another problem.
          > > Where the dtTemp("When") column is not DBNull I need to replace the[/color][/color]
          value of[color=blue][color=green]
          > > another column (dtTemp("When2" ) with a value of a specific variable.
          > > Rows.Add doesn't work (although the books say that if the PK value for[/color][/color]
          the[color=blue][color=green]
          > > record is already there it would replace the data) and there isn't[/color][/color]
          anything[color=blue][color=green]
          > > like "change" or "replace". How can I do this?
          > >
          > > Thanks,
          > >
          > > Claus
          > >
          > >
          > > "Lucas Tam" <REMOVEnntp@rog ers.com> wrote in message
          > > news:Xns95AFC39 7C92C5nntproger scom@140.99.99. 130...[color=darkred]
          > > > "cjobes" <cjobes@nova-tech.org> wrote in news:OAvLiZa1EH A.324
          > > > @TK2MSFTNGP10.p hx.gbl:
          > > >
          > > > > Hi all,
          > > > >
          > > > > I have a date field in a temp table as part of a DataSet. In some[/color]
          > > records[color=darkred]
          > > > > the value is DBNull. how can I trap the error with
          > > > > if dtTemp("When") = ??? Then.....
          > > >
          > > >
          > > > If dtTemp("When") is system.dbnull.v alue then
          > > > Msgbox("oops dbnull!")
          > > > end if
          > > >
          > > >
          > > >
          > > > --
          > > > Lucas Tam (REMOVEnntp@rog ers.com)
          > > > Please delete "REMOVE" from the e-mail address when replying.
          > > > http://members.ebay.com/aboutme/coolspot18/[/color]
          > >
          > >
          > >[/color][/color]


          Comment

          • Cor Ligthert

            #6
            Re: How to trap DBNull?

            Claus,

            Why would you add a row when you have to change an item in a column.
            To give some explanation about items and columns.

            A column is the description of a datatable column in such a column are items
            Therefore
            \\\
            dim mycolumname as string = mytable.columns (0).columnname
            ///
            gives you the name of the column
            \\\
            dim mycolumnitem as string = mytable.rows(0) .item(0) or
            dim mycolumnitem as string = mytable.rows(0) .item(mycolumnn ame)
            ///
            Gives you the first item in the first row

            Therefore you need probably something as
            \\\
            mytable.rows(0) .item(0) = myvalue
            ///
            I hope this helps?

            Cor

            "cjobes" <cjobes@nova-tech.org> schreef in bericht
            news:OZtXnCb1EH A.1124@tk2msftn gp13.phx.gbl...[color=blue]
            > Thanks, that worked.
            >
            > Now that the project doesn't time out anymore, I found another problem.
            > Where the dtTemp("When") column is not DBNull I need to replace the value
            > of
            > another column (dtTemp("When2" ) with a value of a specific variable.
            > Rows.Add doesn't work (although the books say that if the PK value for the
            > record is already there it would replace the data) and there isn't
            > anything
            > like "change" or "replace". How can I do this?
            >
            > Thanks,
            >
            > Claus
            >
            >
            > "Lucas Tam" <REMOVEnntp@rog ers.com> wrote in message
            > news:Xns95AFC39 7C92C5nntproger scom@140.99.99. 130...[color=green]
            >> "cjobes" <cjobes@nova-tech.org> wrote in news:OAvLiZa1EH A.324
            >> @TK2MSFTNGP10.p hx.gbl:
            >>[color=darkred]
            >> > Hi all,
            >> >
            >> > I have a date field in a temp table as part of a DataSet. In some[/color][/color]
            > records[color=green][color=darkred]
            >> > the value is DBNull. how can I trap the error with
            >> > if dtTemp("When") = ??? Then.....[/color]
            >>
            >>
            >> If dtTemp("When") is system.dbnull.v alue then
            >> Msgbox("oops dbnull!")
            >> end if
            >>
            >>
            >>
            >> --
            >> Lucas Tam (REMOVEnntp@rog ers.com)
            >> Please delete "REMOVE" from the e-mail address when replying.
            >> http://members.ebay.com/aboutme/coolspot18/[/color]
            >
            >[/color]


            Comment

            • Ken Tucker [MVP]

              #7
              Re: How to trap DBNull?

              Hi,

              The datarow has an isnull method to tell if a field is dbnull.



              Ken
              -----------------------
              "cjobes" <cjobes@nova-tech.org> wrote in message
              news:OAvLiZa1EH A.324@TK2MSFTNG P10.phx.gbl...
              Hi all,

              I have a date field in a temp table as part of a DataSet. In some records
              the value is DBNull. how can I trap the error with
              if dtTemp("When") = ??? Then.....

              Thanks,

              Claus



              Comment

              Working...