473,795 Members | 2,554 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Diagnos tics.DebuggerNo nUserCodeAttrib ute()_

Public Property SuiteFloor() As String

Get

Try

Return CType(Me(Me.tab leaspnet_getMyI nfo.SuiteFloorC olumn),String)

Catch e As System.InvalidC astException

Throw New System.Data.Str ongTypingExcept ion("The value for column
'SuiteFloor' in table 'aspnet_getMyIn fo' is DBNull.", e)

End Try

End Get

Set

Me(Me.tableaspn et_getMyInfo.Su iteFloorColumn) = 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_getMyIn fo' is DBNull."}

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

Dim MyInfoDataAdapt er As New
dsMyInfoTableAd apters.aspnet_g etMyInfoDataTab leAdapter

Dim MyInfoData As dsMyInfo.aspnet _getMyInfoDataD ataTable

Dim cc As dsMyInfo.aspnet _getCrownCorpDa taRow

MyInfoData = crownDataAdapte r.GetData_Byorg IDLanguageID(la nguageID, orgID)

For Each cc In MyInfoData

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

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

'On all fields below,

'Check that the field does not contain a NULL value

'SuiteFloor

If IsDBNull(cc.Sui teFloor) Then

txtSuiteFloor.T ext = ""

Else

txtSuiteFloor.T ext = 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 4093
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.Diagnos tics.DebuggerNo nUserCodeAttrib ute()_

Public Property SuiteFloor() As String

Get

Try

Return CType(Me(Me.tab leaspnet_getMyI nfo.SuiteFloorC olumn),String)

Catch e As System.InvalidC astException

Throw New System.Data.Str ongTypingExcept ion("The value for column
'SuiteFloor' in table 'aspnet_getMyIn fo' is DBNull.", e)
>From the first look, the error is System.InvalidC astException.
Comment "Throw New System.Data.Str ongTypingExcept ion......." 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.goo glegroups.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.Diagno stics.DebuggerN onUserCodeAttri bute()_

Public Property SuiteFloor() As String

Get

Try

Return CType(Me(Me.tab leaspnet_getMyI nfo.SuiteFloorC olumn),String)

Catch e As System.InvalidC astException

Throw New System.Data.Str ongTypingExcept ion("The value for column
'SuiteFloor' in table 'aspnet_getMyIn fo' is DBNull.", e)
>>From the first look, the error is System.InvalidC astException.

Comment "Throw New System.Data.Str ongTypingExcept ion......." line to
see the real error message.

Feb 15 '07 #3
Show output from Debug:

A first chance exception of type 'System.Invalid CastException' occurred in
Microsoft.Visua lBasic.dll

A first chance exception of type 'System.Data.St rongTypingExcep tion'
occurred in App_Code.pcnwys he.dll

"Alexey Smirnov" <al************ @gmail.comwrote in message
news:11******** **************@ k78g2000cwa.goo glegroups.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.Diagno stics.DebuggerN onUserCodeAttri bute()_

Public Property SuiteFloor() As String

Get

Try

Return CType(Me(Me.tab leaspnet_getMyI nfo.SuiteFloorC olumn),String)

Catch e As System.InvalidC astException

Throw New System.Data.Str ongTypingExcept ion("The value for column
'SuiteFloor' in table 'aspnet_getMyIn fo' is DBNull.", e)
>>From the first look, the error is System.InvalidC astException.

Comment "Throw New System.Data.Str ongTypingExcept ion......." 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.Invalid CastException' occurred in
Microsoft.Visua lBasic.dll
It's here:

If IsDBNull(cc.Sui teFloor) Then

because cc.SuiteFloor is trying to return
CType(Me(Me.tab leaspnet_getMyI nfo.SuiteFloorC olumn),String) where
SuiteFloorColum n has DbNull value.

Why not to do the following:

Public Property SuiteFloor() As String
Get
Try
if isDbNull(Me.tab leaspnet_getMyI nfo.SuiteFloorC olumn)
Return ""
else
Return CType(Me(Me.tab leaspnet_getMyI nfo.SuiteFloorC olumn),String)
Catch e As System.InvalidC astException
Throw New System.Data.Str ongTypingExcept ion("The value for column
'SuiteFloor' in table 'aspnet_getMyIn fo' is DBNull.", e)
End Try
End Get

or

Public Property SuiteFloor() As String
Get
Try
Return CType(Me(Me.tab leaspnet_getMyI nfo.SuiteFloorC olumn),String)
Catch e As System.InvalidC astException
return ""
End Try
End Get

and then instead the

If IsDBNull(cc.Sui teFloor) Then
txtSuiteFloor.T ext = ""
Else
txtSuiteFloor.T ext = cc.SuiteFloor
End If

do simple

txtSuiteFloor.T ext = cc.SuiteFloor

Feb 15 '07 #5

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

Similar topics

19
3607
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 was loaded using a left join from two MS SQL database tables. The workphone element is null because there was no corresponding record from the right side of the join The generated code for retrieving the value of 'Workphone' as a dataset property...
4
3451
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 value. If I access the value of what I am going to pass to the IsDBNull function before I call the IsDBNull function then it does successfully determine that it has a DBNull value. Below is a page that I am using to test. Note: that the value for...
4
3283
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 cast from DBNull to other types. What am I doing wrong?
5
1373
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
3590
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 labels without checking first. Is there a better method to write this than using a bunch of "If" statements? Could it be a function? if so, how would I write it? 'Read the single record While drLeadFeedback.Read() If Not...
4
4016
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 being sent is Null using IsDBNull. I am using the following: if (! IsDBNull(spCurrentHighLgt)) this.ltlCHLTitle.Text = spCurrentHighLgt.toString(); However, I am getting the error that the name "IsDBNull" does not exist in
2
1458
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 pulling a DBNULL value. I was suggestted to add the following IF ELSE and it makes sense to do that : <System.Diagnostics.DebuggerNonUserCodeAttribute()_
4
5261
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 null values in the data table. Unfortunately my code dud not work. Please see my code below. for (int i = 0; i < columnNameInt.Length -1; i++) { try { myDataTable.Columns].DefaultValue = 0; myDataTable.Columns].AllowDBNull = false;
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10213
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10163
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10000
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9040
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.