473,320 Members | 1,939 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

ASPNet Web - DBNull

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
Nov 21 '05 #1
3 3081
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") ) thenEventDescription.Text =
myDataReader.Item("EventDescription")
endif
.

Nov 21 '05 #2
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" <an*******@discussions.microsoft.com> wrote in message
news:17****************************@phx.gbl...
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
.

Nov 21 '05 #3
Thank you that resolve the issue.

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

If Not myDataReader.isdbnull(0) then <-- where 0 is item index ofEventDescription (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" <an*******@discussions.microsoft.com> wrote in messagenews:17****************************@phx.gbl...
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
>.
>

.

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: DraguVaso | last post by:
Hi, Something I don't understand about a Typed DataSet: When a value in the DataSet is DBNull, it throws this error: "Cannot get value because it is DBNull". But aren't Typed DataSets...
4
by: Michael Culley | last post by:
Which is better: SomeValue is DBNull or SomeValue == DBNull.Value Thanks, Michael Culley
11
by: Patrick.O.Ige | last post by:
When i try and use this (Where Unit is a column in my Table):- If Unit Is DBNull.Value Then Return "1" Else Return "2" End If I always have 2 returned! Even when Unit is NULL! I want a...
4
by: Tina | last post by:
I have instantiated an insertRow for a dataset. I now want to make the GLCode DBNull. I have tried: insertRow.GLCode = Convert.dbnull insertRow.GLCode = Convert.dbnull(insertRow.GLCode) and...
8
by: MattB | last post by:
Hello. I have a vb.net (asp.net) application that uses ado.net datasets. At one point, I need to check a text field in a DataTable to see if there's any text in it before performing text operations...
10
by: Bob | last post by:
I'm sure there's a good reason, I just haven't been able to think of it - why didn't MS allow "DBNull" values to simply be a null (Nothing)? Bob
6
by: tshad | last post by:
I have a value coming from my Object (or it could also be from a SqlDbReader) where I need to test for DBNull and 0. I tried to do it in one call: if (not (newPosition.ReportsTo is...
6
by: cj | last post by:
in the command window I get: ? result {System.DBNull} : {System.DBNull} I need to check for this in code. I then tested in the command window if result = system.DBNull 'DBNull' is a type...
19
by: Dave | last post by:
If Iwant to check if dataset1.SelectQuery1.column1 == System.DBNull.Value. How do I do this? What I wrote above will give an error. -- L. A. Jones
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.