ASPNet Web - DBNull

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
 
M

Mike

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
 
G

Greg Burns

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
 
M

Mike

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




.
 

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

Top