allow NULLS

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.
 
D

Daniel Walzenbach

Mike,

try the following:

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

HTHs

Daniel Walzenbach
 
M

Mike

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

Daniel Walzenbach

Mike,

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

Greetings

Daniel
 
M

Mike

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
 
M

Mike

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
 
R

Richard

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.
 
M

[MSFT]

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top