IsDBNull problem

I am probably doing this wrong

If IsDBNull(EDFRow.EStart)Then

Me.EStartDateTimePicker.Checked =False

Else

Me.EStartDateTimePicker.Checked =True

EndIf

I get the error that the filed is dbnull

Can someone please explain this.

Davids Learning

[783 byte] By [DavidsLearning] at [2007-12-22]
# 1

Are you saying that IsDBNull is returing true or that an error is being generated?

If its the later then post the exact error message.

What sort of object is EDFRow.EStart?

Should you perhaps be testing if it's Nothing

JanHyde at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 2

Didnt post all of my code, sorry

Dim EDFRow As ST102ADataSet.EDFRow

If Me.ENameListBox.SelectedItems.Count = 1 Then

EDFRow = ST102ADataSet.EDF.FindByEName(Me.ENameListBox.SelectedValue.ToString)

If IsDBNull(EDFRow.EStart) Then

Me.EStartDateTimePicker.Checked = False

Else

Me.EStartDateTimePicker.Checked = True

End If

EDFRow.EStart is a field in a table that is a smalldate

IsNothing didnt work

IsNothing I thought would not work on a null field in a table, I thought IsNothing refers to a control only?

I am trying to find out if the fields value for the record is null, then if it is , get a date picker to not show a date until the field has data in it.

Davids Learning

DavidsLearning at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 3

I only suggested testing for Nothing in case you object had nothing to do with databases.

Anyhow, you still didn't answer my question.

JanHyde at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 4

It is an exeption error

It says that the field I am refering to is DBNull

It stops my code from executing to give me that error

Sorry

Davids Learning

DavidsLearning at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 5

Isdbnull Method
http://msdn2.microsoft.com/en-us/library/tckcces5.aspx

Returns a Boolean value indicating whether an expression evaluates to the System.DBNull class.

DBNull Class
Represents a nonexistent value. This class cannot be inherited
DBnull is in fact system.dbnull and is a class, Null (Nothing) in vb is not the same as dbnull. So you need to be careful that you are using the right one otherwise it may provide strange results.

A search on the forums on isdbnull will detail it and potential pitfalls that can cause confusing results. I'd suggest having a look at these and see if either of these actually helps you out.

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=555922&SiteID=1

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=129341&SiteID=1

Which line specifically is throwing the exception ?

and what value do you think should be in the database for this item ?

spotty at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 6

This is the exact error

The value for column 'EStart' in table 'EDF' is DBNull.

<System.Diagnostics.DebuggerNonUserCodeAttribute()> _

Public Property EStart() As Date

Get

Try

Return CType(Me(Me.tableEDF.EStartColumn),Date)

Catch e As System.InvalidCastException

Throw New System.Data.StrongTypingException("The value for column 'EStart' in table 'EDF' is DBNull.", e) <<This Line

End Try

End Get

Set

Me(Me.tableEDF.EStartColumn) = value

End Set

End Property

There is nothing in the field in the database - it is a field that will hold a future date.

Davids Learning

DavidsLearning at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 7

Did you check the DataSet Designer that the Column is not set to ThrowException on DBNull?

spotty at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 8

Yes and it wont let me, this is the error

For columns not defined as System.String, the only valid value is (Throw exception).

This is a date field.

Is there a work around for this.

Davids Learning

DavidsLearning at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 9

If (EDFRow.isEStartNull = True) Then

Me.EStartDateTimePicker.Checked = False

Else

Me.EStartDateTimePicker.Checked = True

End If

isEStartNull Method is provided by default for typed datasets. :)

TkNeo at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 10

You are assuming that this line actually returns a value.

EDFRow = ST102ADataSet.EDF.FindByEName(Me.ENameListBox.SelectedValue.ToString)

Test EDFRow as follows:

If EDFRow IsNot Nothing Then

'do your other code here

Else

'do your else code here

End if

IbrahimY at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic Language...