IsDBNULL Error ~ Help Please....

B

Brad Isaacs

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_getMyInfoDataTableAdapter

Dim MyInfoData As dsMyInfo.aspnet_getMyInfoDataDataTable

Dim cc As dsMyInfo.aspnet_getCrownCorpDataRow

MyInfoData = crownDataAdapter.GetData_ByorgIDLanguageID(languageID, 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
 
G

Guest

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.
 
B

Brad Isaacs

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.................
 
B

Brad Isaacs

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
 
G

Guest

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
 

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

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top