Column contains NULL data

Discussion in 'ASP .Net' started by DaveF, Jun 14, 2004.

  1. DaveF

    DaveF Guest

    dr.GetString(2) is Null how do I deal with that?

    Line 72: Do While dr.Read
    Line 73: aString = aString + CStr(dr.GetValue(0)) + ":" &
    dr.GetString(1) + ":" & dr.GetString(2) + ":" + dr.GetString(3) + ":"
    Line 74: Loop

    --


    David
    DaveF, Jun 14, 2004
    #1
    1. Advertising

  2. DaveF

    Curt_C [MVP] Guest

    if(dr.GetValue(0) != null)
    ....
    else
    .....


    --
    Curt Christianson
    Owner/Lead Developer, DF-Software
    Site: http://www.Darkfalz.com
    Blog: http://blog.Darkfalz.com


    "DaveF" <> wrote in message
    news:%23M9%...
    > dr.GetString(2) is Null how do I deal with that?
    >
    > Line 72: Do While dr.Read
    > Line 73: aString = aString + CStr(dr.GetValue(0)) + ":" &
    > dr.GetString(1) + ":" & dr.GetString(2) + ":" + dr.GetString(3) + ":"
    > Line 74: Loop
    >
    > --
    >
    >
    > David
    >
    >
    Curt_C [MVP], Jun 14, 2004
    #2
    1. Advertising

  3. Dave,

    If Not dr.GetString(2) Is System.DBNull.Value Then

    End If

    --
    Sincerely,

    S. Justin Gengo, MCP
    Web Developer / Programmer

    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzsche
    "DaveF" <> wrote in message
    news:%23M9%...
    > dr.GetString(2) is Null how do I deal with that?
    >
    > Line 72: Do While dr.Read
    > Line 73: aString = aString + CStr(dr.GetValue(0)) + ":" &
    > dr.GetString(1) + ":" & dr.GetString(2) + ":" + dr.GetString(3) + ":"
    > Line 74: Loop
    >
    > --
    >
    >
    > David
    >
    >
    S. Justin Gengo, Jun 14, 2004
    #3
  4. On Mon, 14 Jun 2004 15:25:48 -0400, DaveF <> wrote:

    > dr.GetString(2) is Null how do I deal with that?
    >
    > Line 72: Do While dr.Read
    > Line 73: aString = aString + CStr(dr.GetValue(0)) + ":" &
    > dr.GetString(1) + ":" & dr.GetString(2) + ":" + dr.GetString(3) + ":"
    > Line 74: Loop
    >


    You have to manually check the case that it is DbNull.Value. I usually
    create a StringUtil class w/ static methods that do stuff like this ()

    Public Static Function StringUtil.ToString(val as object) as string
    if ((val = DbNull.value) orelse (val = null)) Then
    return String.empty
    else
    return val.ToString()
    end if
    end function

    sorry, haven't done vb.net in awhile, so use as a guideline...

    --
    Craig Deelsnyder
    Microsoft MVP - ASP/ASP.NET
    Craig Deelsnyder, Jun 14, 2004
    #4
  5. DaveF

    LOSER Guest

    Or you could just do a ToString on it....Intellisense won't work but
    it will convert DBnull values to "".

    On Mon, 14 Jun 2004 15:04:26 -0500, "Craig Deelsnyder"
    <cdeelsny@no_spam_4_meyahoo.com> wrote:

    >On Mon, 14 Jun 2004 15:25:48 -0400, DaveF <> wrote:
    >
    >> dr.GetString(2) is Null how do I deal with that?
    >>
    >> Line 72: Do While dr.Read
    >> Line 73: aString = aString + CStr(dr.GetValue(0)) + ":" &
    >> dr.GetString(1) + ":" & dr.GetString(2) + ":" + dr.GetString(3) + ":"
    >> Line 74: Loop
    >>

    >
    >You have to manually check the case that it is DbNull.Value. I usually
    >create a StringUtil class w/ static methods that do stuff like this ()
    >
    >Public Static Function StringUtil.ToString(val as object) as string
    > if ((val = DbNull.value) orelse (val = null)) Then
    > return String.empty
    > else
    > return val.ToString()
    > end if
    >end function
    >
    >sorry, haven't done vb.net in awhile, so use as a guideline...
    LOSER, Jun 14, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. James Dyer
    Replies:
    5
    Views:
    638
  2. carlos perez
    Replies:
    0
    Views:
    405
    carlos perez
    Jun 8, 2004
  3. Replies:
    5
    Views:
    26,486
    Mike Schilling
    Mar 29, 2006
  4. Mauricio Fernández
    Replies:
    0
    Views:
    275
    Mauricio Fernández
    Nov 28, 2004
  5. Hadmut Danisch

    syscall: string contains null byte

    Hadmut Danisch, Aug 26, 2010, in forum: Ruby
    Replies:
    0
    Views:
    116
    Hadmut Danisch
    Aug 26, 2010
Loading...

Share This Page