allow NULLS

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

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,

try the following:

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

HTHs

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

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

Greetings

Daniel
 
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
 
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
 
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.
 
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
 
Back
Top