473,322 Members | 1,610 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,322 software developers and data experts.

IsDBNULL Error ~ Help Please....

I am using ASP.NET 2.0 codebehind Visual Basic, Visual Studio 2005

Working with DataSet creating a Data Access Layer via VS 2005.

My error is when the code that is prewritten by VS 2005 Casts to String but
the data inside the column is a NULL.

Code prewritten by visual studio:
<System.Diagnostics.DebuggerNonUserCodeAttribute() _

Public Property SuiteFloor() As String

Get

Try

Return CType(Me(Me.tableaspnet_getMyInfo.SuiteFloorColumn ),String)

Catch e As System.InvalidCastException

Throw New System.Data.StrongTypingException("The value for column
'SuiteFloor' in table 'aspnet_getMyInfo' is DBNull.", e)

End Try

End Get

Set

Me(Me.tableaspnet_getMyInfo.SuiteFloorColumn) = value

End Set

End Property

It throws an error becuase the value in the database is NULL.
{"The value for column 'SuiteFloor' in table 'aspnet_getMyInfo' is DBNull."}

I tried to perform this code in my .aspx page:
Public Sub populateMyInfoData(ByVal orgID As String)

Dim MyInfoDataAdapter As New
dsMyInfoTableAdapters.aspnet_getMyInfoDataTableAda pter

Dim MyInfoData As dsMyInfo.aspnet_getMyInfoDataDataTable

Dim cc As dsMyInfo.aspnet_getCrownCorpDataRow

MyInfoData = crownDataAdapter.GetData_ByorgIDLanguageID(languag eID, orgID)

For Each cc In MyInfoData

'Response.Write("Suite/Floor: " & cc.SuiteFloor & "<br>")

'Response.Write("Street Address: " & cc.StreetAddress & "<br>")

'On all fields below,

'Check that the field does not contain a NULL value

'SuiteFloor

If IsDBNull(cc.SuiteFloor) Then

txtSuiteFloor.Text = ""

Else

txtSuiteFloor.Text = cc.SuiteFloor

End If
This had no affect because the error is THROWN when inside the Property
method.

Does anyone have any ideas how to resolve this issue?

Thanks in advance,

~Brad

------------------------------
Brad Isaacs
bi*****@rogers.com
Feb 15 '07 #1
4 4074
On Feb 15, 9:14 pm, "Brad Isaacs" <bisa...@rogers.comwrote:
I am using ASP.NET 2.0 codebehind Visual Basic, Visual Studio 2005

Working with DataSet creating a Data Access Layer via VS 2005.

My error is when the code that is prewritten by VS 2005 Casts to String but
the data inside the column is a NULL.

Code prewritten by visual studio:
<System.Diagnostics.DebuggerNonUserCodeAttribute() _

Public Property SuiteFloor() As String

Get

Try

Return CType(Me(Me.tableaspnet_getMyInfo.SuiteFloorColumn ),String)

Catch e As System.InvalidCastException

Throw New System.Data.StrongTypingException("The value for column
'SuiteFloor' in table 'aspnet_getMyInfo' is DBNull.", e)
>From the first look, the error is System.InvalidCastException.
Comment "Throw New System.Data.StrongTypingException......." line to
see the real error message.

Feb 15 '07 #2
Alexey,

I did as you mentioned and received the same error:

InnerException:::{"Conversion from type 'DBNull' to type 'String' is not
valid."}

In addition, this code is prewritten by Visual Studio 2005 and everytime I
comment out a line, it just recreates the file with a new name.
Any ideas???

very frustrating.................
"Alexey Smirnov" <al************@gmail.comwrote in message
news:11**********************@k78g2000cwa.googlegr oups.com...
On Feb 15, 9:14 pm, "Brad Isaacs" <bisa...@rogers.comwrote:
>I am using ASP.NET 2.0 codebehind Visual Basic, Visual Studio 2005

Working with DataSet creating a Data Access Layer via VS 2005.

My error is when the code that is prewritten by VS 2005 Casts to String
but
the data inside the column is a NULL.

Code prewritten by visual studio:
<System.Diagnostics.DebuggerNonUserCodeAttribute( )_

Public Property SuiteFloor() As String

Get

Try

Return CType(Me(Me.tableaspnet_getMyInfo.SuiteFloorColumn ),String)

Catch e As System.InvalidCastException

Throw New System.Data.StrongTypingException("The value for column
'SuiteFloor' in table 'aspnet_getMyInfo' is DBNull.", e)
>>From the first look, the error is System.InvalidCastException.

Comment "Throw New System.Data.StrongTypingException......." line to
see the real error message.

Feb 15 '07 #3
Show output from Debug:

A first chance exception of type 'System.InvalidCastException' occurred in
Microsoft.VisualBasic.dll

A first chance exception of type 'System.Data.StrongTypingException'
occurred in App_Code.pcnwyshe.dll

"Alexey Smirnov" <al************@gmail.comwrote in message
news:11**********************@k78g2000cwa.googlegr oups.com...
On Feb 15, 9:14 pm, "Brad Isaacs" <bisa...@rogers.comwrote:
>I am using ASP.NET 2.0 codebehind Visual Basic, Visual Studio 2005

Working with DataSet creating a Data Access Layer via VS 2005.

My error is when the code that is prewritten by VS 2005 Casts to String
but
the data inside the column is a NULL.

Code prewritten by visual studio:
<System.Diagnostics.DebuggerNonUserCodeAttribute( )_

Public Property SuiteFloor() As String

Get

Try

Return CType(Me(Me.tableaspnet_getMyInfo.SuiteFloorColumn ),String)

Catch e As System.InvalidCastException

Throw New System.Data.StrongTypingException("The value for column
'SuiteFloor' in table 'aspnet_getMyInfo' is DBNull.", e)
>>From the first look, the error is System.InvalidCastException.

Comment "Throw New System.Data.StrongTypingException......." line to
see the real error message.

Feb 15 '07 #4
On Feb 15, 10:42 pm, "Brad Isaacs" <bisa...@rogers.comwrote:
Show output from Debug:

A first chance exception of type 'System.InvalidCastException' occurred in
Microsoft.VisualBasic.dll
It's here:

If IsDBNull(cc.SuiteFloor) Then

because cc.SuiteFloor is trying to return
CType(Me(Me.tableaspnet_getMyInfo.SuiteFloorColumn ),String) where
SuiteFloorColumn has DbNull value.

Why not to do the following:

Public Property SuiteFloor() As String
Get
Try
if isDbNull(Me.tableaspnet_getMyInfo.SuiteFloorColumn )
Return ""
else
Return CType(Me(Me.tableaspnet_getMyInfo.SuiteFloorColumn ),String)
Catch e As System.InvalidCastException
Throw New System.Data.StrongTypingException("The value for column
'SuiteFloor' in table 'aspnet_getMyInfo' is DBNull.", e)
End Try
End Get

or

Public Property SuiteFloor() As String
Get
Try
Return CType(Me(Me.tableaspnet_getMyInfo.SuiteFloorColumn ),String)
Catch e As System.InvalidCastException
return ""
End Try
End Get

and then instead the

If IsDBNull(cc.SuiteFloor) Then
txtSuiteFloor.Text = ""
Else
txtSuiteFloor.Text = cc.SuiteFloor
End If

do simple

txtSuiteFloor.Text = cc.SuiteFloor

Feb 15 '07 #5

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

Similar topics

19
by: jim | last post by:
This line of code returns error 13, cast from 'DBNull' to type 'String' is not valid If IsDBNull(Clinics.Clinics.Item(A).Workphone) The <other code End I Clinics.Clinics is a dataset that...
4
by: Jim | last post by:
I am having a problem with the IsDBNull function. When it checks what type of value is contained in the parameter that is passed to it, it does not successfully determine that it has a DBNull...
4
by: BillG | last post by:
I have the following line in my code paid.MonthsPaid = IIf(IsDBNull(Row("MonthsPaid")), Integer.MinValue, Convert.ToInt16(Row("MonthsPaid"))) and I get the error message Object cannot be...
5
by: luna | last post by:
how to i use isdbnull on two tables ? im pulling out the data with a stored procedure like this :- CREATE PROCEDURE search @search varchar(8) AS
3
by: Paul D. Fox | last post by:
I have this code snippet below where I'm loading all the labels based upon the retrieved record from the DataReader. Unfortunatley, some of the values are null, so I can't explicitly set the...
4
by: sck10 | last post by:
Hello (converting from vb to c#), Is there a way to test the value of null of a particular field of a dataset from SQL Server? I am going through a dataset and trying to determine if the value...
2
by: Brad Isaacs | last post by:
ASp.NET 2.0 , Visual Studio 2005 I am working with the Add NEw Item >DataSet I have created my Dataset and call it, when I run my project, I receive an error message because the dataset is...
4
by: RICALJE | last post by:
Hi All, Could you help me in my problem in working on a project that imports excel file to a datatable the validation is to catch all null values in the excel file because it will should not allow...
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...
1
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: 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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.