PC Review


Reply
Thread Tools Rate Thread

ASPNet Web - DBNull

 
 
Mike
Guest
Posts: n/a
 
      6th Aug 2004
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


 
Reply With Quote
 
 
 
 
Mike
Guest
Posts: n/a
 
      6th Aug 2004
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





>-----Original Message-----
>if not isdbnull(myDataReader.Item("EventDescription") )

then
>EventDescription.Text =
>myDataReader.Item("EventDescription")
>endif
>.
>

 
Reply With Quote
 
Greg Burns
Guest
Posts: n/a
 
      6th Aug 2004
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

"Mike" <(E-Mail Removed)> wrote in message
news:173401c47bce$8d2d6b60$(E-Mail Removed)...
> 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
>
>
>
>
>
> >-----Original Message-----
> >if not isdbnull(myDataReader.Item("EventDescription") )

> then
> >EventDescription.Text =
> >myDataReader.Item("EventDescription")
> >endif
> >.
> >



 
Reply With Quote
 
Mike
Guest
Posts: n/a
 
      7th Aug 2004
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
>
>"Mike" <(E-Mail Removed)> wrote in

message
>news:173401c47bce$8d2d6b60$(E-Mail Removed)...
>> 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
>>
>>
>>
>>
>>
>> >-----Original Message-----
>> >if not isdbnull(myDataReader.Item("EventDescription") )

>> then
>> >EventDescription.Text =
>> >myDataReader.Item("EventDescription")
>> >endif
>> >.
>> >

>
>
>.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
dbnull segue Microsoft ASP .NET 1 29th Jan 2008 12:10 AM
Is the aspnet account called "aspnet" for all non-English versions of Windows and IIS? torus@tpg.com.au Microsoft ASP .NET 7 23rd Mar 2007 04:00 AM
1-0-DBNull Brenny Microsoft C# .NET 3 7th Jan 2006 08:51 PM
Upgrade from aspnet 1.1 to aspnet 2.0 Gary Nelson Microsoft ASP .NET 2 14th Oct 2005 06:16 PM
DBNull JD Microsoft Dot NET Framework Forms 3 12th Jul 2004 04:31 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:04 PM.