allow NULLS

Discussion in 'ASP .Net' started by Mike, Jun 20, 2004.

  1. Mike

    Mike Guest

    The current databas structure that i'm working with allowed NULL's an now
    I'm converting the app to .NET and it will not allow NULLs in the fields
    when populated.
    So my question is, how can i hande NULL's being pulled from the DB now?

    When I try to access a page and if the field is NULL I get an error:

    i do i fix this? I'm using VB.NET for coding

    Cast from type 'DBNull' to type 'String' is not valid.
     
    Mike, Jun 20, 2004
    #1
    1. Advertising

  2. Mike,

    try the following:

    if not isdbnull(yourvalue) then
    ' do sth
    end if

    HTHs

    Daniel Walzenbach


    "Mike" <> schrieb im Newsbeitrag
    news:...
    > The current databas structure that i'm working with allowed NULL's an now
    > I'm converting the app to .NET and it will not allow NULLs in the fields
    > when populated.
    > So my question is, how can i hande NULL's being pulled from the DB now?
    >
    > When I try to access a page and if the field is NULL I get an error:
    >
    > i do i fix this? I'm using VB.NET for coding
    >
    > Cast from type 'DBNull' to type 'String' is not valid.
    >
    >
    >
    >
     
    Daniel Walzenbach, Jun 20, 2004
    #2
    1. Advertising

  3. Use iif turner operator available in visual basic, see reference below:
    http://msdn.microsoft.com/library/en-us/vblr7/html/vafctiif.asp

    Dim toReturn As String = IIf(Expression:=IsDBNull(currentRow.Item(0)),
    TruePart:="",
    FalsePart:=currentRow.Item(0))

    So in above case if currentRow.Item(0) is dbnull, then it will return empty
    string, otherwise
    it will return currentRow.Item(0).

    --
    Hope this helps,
    Zeeshan Mustafa, MCSD


    "Mike" <> wrote in message
    news:...
    > The current databas structure that i'm working with allowed NULL's an now
    > I'm converting the app to .NET and it will not allow NULLs in the fields
    > when populated.
    > So my question is, how can i hande NULL's being pulled from the DB now?
    >
    > When I try to access a page and if the field is NULL I get an error:
    >
    > i do i fix this? I'm using VB.NET for coding
    >
    > Cast from type 'DBNull' to type 'String' is not valid.
    >
    >
    >
    >
     
    M. Zeeshan Mustafa, Jun 21, 2004
    #3
  4. Mike

    Mike Guest

    thanks but im not populating a grid with empty values, I'm populating Text
    boxes and some values are blank at times



    "M. Zeeshan Mustafa" <> wrote in message
    news:...
    > Use iif turner operator available in visual basic, see reference below:
    > http://msdn.microsoft.com/library/en-us/vblr7/html/vafctiif.asp
    >
    > Dim toReturn As String = IIf(Expression:=IsDBNull(currentRow.Item(0)),
    > TruePart:="",
    > FalsePart:=currentRow.Item(0))
    >
    > So in above case if currentRow.Item(0) is dbnull, then it will return

    empty
    > string, otherwise
    > it will return currentRow.Item(0).
    >
    > --
    > Hope this helps,
    > Zeeshan Mustafa, MCSD
    >
    >
    > "Mike" <> wrote in message
    > news:...
    > > The current databas structure that i'm working with allowed NULL's an

    now
    > > I'm converting the app to .NET and it will not allow NULLs in the fields
    > > when populated.
    > > So my question is, how can i hande NULL's being pulled from the DB now?
    > >
    > > When I try to access a page and if the field is NULL I get an error:
    > >
    > > i do i fix this? I'm using VB.NET for coding
    > >
    > > Cast from type 'DBNull' to type 'String' is not valid.
    > >
    > >
    > >
    > >

    >
    >
    >
    >
     
    Mike, Jun 21, 2004
    #4
  5. Mike,

    what exactly are you trying to do? Could you provide some more information
    plz?

    Greetings

    Daniel

    "Mike" <> schrieb im Newsbeitrag
    news:enKN6A%...
    > thanks but im not populating a grid with empty values, I'm populating Text
    > boxes and some values are blank at times
    >
    >
    >
    > "M. Zeeshan Mustafa" <> wrote in message
    > news:...
    > > Use iif turner operator available in visual basic, see reference below:
    > > http://msdn.microsoft.com/library/en-us/vblr7/html/vafctiif.asp
    > >
    > > Dim toReturn As String = IIf(Expression:=IsDBNull(currentRow.Item(0)),
    > > TruePart:="",
    > > FalsePart:=currentRow.Item(0))
    > >
    > > So in above case if currentRow.Item(0) is dbnull, then it will return

    > empty
    > > string, otherwise
    > > it will return currentRow.Item(0).
    > >
    > > --
    > > Hope this helps,
    > > Zeeshan Mustafa, MCSD
    > >
    > >
    > > "Mike" <> wrote in message
    > > news:...
    > > > The current databas structure that i'm working with allowed NULL's an

    > now
    > > > I'm converting the app to .NET and it will not allow NULLs in the

    fields
    > > > when populated.
    > > > So my question is, how can i hande NULL's being pulled from the DB

    now?
    > > >
    > > > When I try to access a page and if the field is NULL I get an error:
    > > >
    > > > i do i fix this? I'm using VB.NET for coding
    > > >
    > > > Cast from type 'DBNull' to type 'String' is not valid.
    > > >
    > > >
    > > >
    > > >

    > >
    > >
    > >
    > >

    >
    >
     
    Daniel Walzenbach, Jun 21, 2004
    #5
  6. Mike

    Mike Guest

    whats happening is that I have a main page (datagrid) and when a user
    highlights a row and clicks the Edit button it takes them to a detailed edit
    screen and some of the fields that are being pulled back from the database
    have <NULL> in the fields instead of data (IE: Scooby) If the column has
    <NULL> I'm getting an error



    "Daniel Walzenbach" <> wrote in
    message news:OVscvF%...
    > Mike,
    >
    > what exactly are you trying to do? Could you provide some more information
    > plz?
    >
    > Greetings
    >
    > Daniel
    >
    > "Mike" <> schrieb im Newsbeitrag
    > news:enKN6A%...
    > > thanks but im not populating a grid with empty values, I'm populating

    Text
    > > boxes and some values are blank at times
    > >
    > >
    > >
    > > "M. Zeeshan Mustafa" <> wrote in

    message
    > > news:...
    > > > Use iif turner operator available in visual basic, see reference

    below:
    > > > http://msdn.microsoft.com/library/en-us/vblr7/html/vafctiif.asp
    > > >
    > > > Dim toReturn As String = IIf(Expression:=IsDBNull(currentRow.Item(0)),
    > > > TruePart:="",
    > > > FalsePart:=currentRow.Item(0))
    > > >
    > > > So in above case if currentRow.Item(0) is dbnull, then it will return

    > > empty
    > > > string, otherwise
    > > > it will return currentRow.Item(0).
    > > >
    > > > --
    > > > Hope this helps,
    > > > Zeeshan Mustafa, MCSD
    > > >
    > > >
    > > > "Mike" <> wrote in message
    > > > news:...
    > > > > The current databas structure that i'm working with allowed NULL's

    an
    > > now
    > > > > I'm converting the app to .NET and it will not allow NULLs in the

    > fields
    > > > > when populated.
    > > > > So my question is, how can i hande NULL's being pulled from the DB

    > now?
    > > > >
    > > > > When I try to access a page and if the field is NULL I get an error:
    > > > >
    > > > > i do i fix this? I'm using VB.NET for coding
    > > > >
    > > > > Cast from type 'DBNull' to type 'String' is not valid.
    > > > >
    > > > >
    > > > >
    > > > >
    > > >
    > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    Mike, Jun 22, 2004
    #6
  7. Mike

    Mike Guest

    whats happening is that I have a main page (datagrid) and when a user
    highlights a row and clicks the Edit button it takes them to a detailed edit
    screen and some of the fields that are being pulled back from the database
    have <NULL> in the fields instead of data (IE: Scooby) If the column has
    <NULL> I'm getting an error
    on the field name that has <NULL> in it but if the column is blank it works
    fine.
    I just need to get around <NULL> if it is in column instead of data

    Cast from type 'DBNull' to type 'String' is not valid





    "Daniel Walzenbach" <> wrote in
    message news:OVscvF%...
    > Mike,
    >
    > what exactly are you trying to do? Could you provide some more information
    > plz?
    >
    > Greetings
    >
    > Daniel
    >
    > "Mike" <> schrieb im Newsbeitrag
    > news:enKN6A%...
    > > thanks but im not populating a grid with empty values, I'm populating

    Text
    > > boxes and some values are blank at times
    > >
    > >
    > >
    > > "M. Zeeshan Mustafa" <> wrote in

    message
    > > news:...
    > > > Use iif turner operator available in visual basic, see reference

    below:
    > > > http://msdn.microsoft.com/library/en-us/vblr7/html/vafctiif.asp
    > > >
    > > > Dim toReturn As String = IIf(Expression:=IsDBNull(currentRow.Item(0)),
    > > > TruePart:="",
    > > > FalsePart:=currentRow.Item(0))
    > > >
    > > > So in above case if currentRow.Item(0) is dbnull, then it will return

    > > empty
    > > > string, otherwise
    > > > it will return currentRow.Item(0).
    > > >
    > > > --
    > > > Hope this helps,
    > > > Zeeshan Mustafa, MCSD
    > > >
    > > >
    > > > "Mike" <> wrote in message
    > > > news:...
    > > > > The current databas structure that i'm working with allowed NULL's

    an
    > > now
    > > > > I'm converting the app to .NET and it will not allow NULLs in the

    > fields
    > > > > when populated.
    > > > > So my question is, how can i hande NULL's being pulled from the DB

    > now?
    > > > >
    > > > > When I try to access a page and if the field is NULL I get an error:
    > > > >
    > > > > i do i fix this? I'm using VB.NET for coding
    > > > >
    > > > > Cast from type 'DBNull' to type 'String' is not valid.
    > > > >
    > > > >
    > > > >
    > > > >
    > > >
    > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    Mike, Jun 22, 2004
    #7
  8. Mike

    Richard Guest

    Just create a function like this:

    Public Function NullHelper(ByVal obj As Object) As String
    If IsDBNull(obj) Then Return String.Empty
    Return obj.ToString()
    End Function

    If check if the value is null and if it is, it will return a empty string.



    "Mike" <> schreef in bericht
    news:...
    > The current databas structure that i'm working with allowed NULL's an now
    > I'm converting the app to .NET and it will not allow NULLs in the fields
    > when populated.
    > So my question is, how can i hande NULL's being pulled from the DB now?
    >
    > When I try to access a page and if the field is NULL I get an error:
    >
    > i do i fix this? I'm using VB.NET for coding
    >
    > Cast from type 'DBNull' to type 'String' is not valid.
    >
    >
    >
    >
     
    Richard, Jun 22, 2004
    #8
  9. Mike

    [MSFT] Guest

    Hi Mike,

    Is the TextBox bound to a Dataset? If so, you may set the TextBox's
    DataBings property. In Binding for Text, you can specify a custom binding
    expression. For example, a function like Richard suggested.

    Luke
     
    [MSFT], Jun 22, 2004
    #9
    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. Bob

    Problem with nulls

    Bob, Jul 2, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    336
  2. Bill

    Inputting NULLS?

    Bill, Dec 11, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    373
    Suresh
    Dec 11, 2003
  3. =?Utf-8?B?U2NvdHRfZnJvbV9DYXJlbWF0aWM=?=

    allow nulls in strongly typed data set asp.net

    =?Utf-8?B?U2NvdHRfZnJvbV9DYXJlbWF0aWM=?=, Jun 14, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    3,576
    =?Utf-8?B?U2NvdHRfZnJvbV9DYXJlbWF0aWM=?=
    Jun 14, 2006
  4. Jeff
    Replies:
    2
    Views:
    979
    clintonG
    Sep 19, 2006
  5. Ryan Taylor
    Replies:
    1
    Views:
    710
    Ryan Taylor
    Sep 9, 2004
Loading...

Share This Page