ASPNet Web - DBNull

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

Mike

Hello,

I have develop an apsnet page using vb language. I'm
currently retriving data from the database. I have two
fields that have null values. I get the following error

Cast from type 'DBNull' to type 'String' is not valid.
Description: An unhandled exception occurred during the
execution of the current web request. Please review the
stack trace for more information about the error and where
it originated in the code.

Exception Details: System.InvalidCastException: Cast from
type 'DBNull' to type 'String' is not valid.

Source Error:


Line 54: '// So, to get the correct
value, I simply subtract 1.
Line 55: EventDescription.Text =
myDataReader.Item("EventDescription")
Line 56: EventStartTime.Text =
myDataReader.item("EventStartTime")
Line 57: EventPhone.Text = myDataReader.Item
("EventPhone")
Line 58:

Any help is really appreciate
Thanks
 
I get the following error now.

Compiler Error Message: BC30451: Name 'isdubll' is not
declared.

Source Error:



Line 56:
Line 57: '//EventStartTime.Text =
myDataReader.item("EventStartTime")
Line 58: If not isdubll(mydatareader.item
("EventStartTime")) then
Line 59: EventStartTime.Text =
myDataReader.Item("EventStartTime")
Line 60: end if
 
Try

If Not myDataReader.isdbnull(0) then <-- where 0 is item index of
EventDescription (unfortunately can't use field name here)

or

If Not myDataReader.Item("EventDescription") Is DbNull.Value Then

or better yet

If data is in SQL Server remove the null at the database using:

SELECT ISNULL(EventDescription,'') AS EventDescription
FROM <blah>

HTH,
Greg
 
Thank you that resolve the issue.

Mike
-----Original Message-----
Try

If Not myDataReader.isdbnull(0) then <-- where 0 is item index of
EventDescription (unfortunately can't use field name here)

or

If Not myDataReader.Item("EventDescription") Is DbNull.Value Then

or better yet

If data is in SQL Server remove the null at the database using:

SELECT ISNULL(EventDescription,'') AS EventDescription
FROM <blah>

HTH,
Greg




.
 
Back
Top