Wrox Programmer Forums
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 12th, 2005, 05:49 AM
Registered User
 
Join Date: Jan 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dealing with NULL values

Hi - back again :D

I'm having a problem dealing with NULL values

All I want to do is use a value to populate the text of a label object, as in:

    lblText.text = dr("Field1")
(where dr = a datareader)

However if the value was NULL I got the following:

    "Cast from type 'DBNull' to type 'String' is not valid. "

So I put the following in to check for NULLs

    IfNot dr.Item("Field1").Value Is DBNull.Value Then
    lblText.text = dr("Field1")
    End if

This is fine if it IS null, but if there actually is value I now get:

    "Public member 'Value' on type 'String' not found"

I have no idea what this means or how to deal with it. Any advice???


 
Old January 12th, 2005, 06:37 AM
Registered User
 
Join Date: Jan 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Solved it! Remarkable what a good night's sleep can do :)

It was the "value" operator on the first part of the check (IfNot dr.Item("Field1").Value ...)

By removing that it has solved it. Code now reads:

If Not dr.Item("Field1") Is DBNull.Value Then
    lblText.text = dr("Field1")
End if







Similar Threads
Thread Thread Starter Forum Replies Last Post
Null values jmcgranahan BOOK: Access 2003 VBA Programmer's Reference 0 August 29th, 2006 02:25 PM
Passing null values maddy137 ASP.NET 1.0 and 1.1 Basics 1 May 7th, 2006 12:26 PM
Dealing with duplicate rows/column values SQLScott SQL Server 2000 2 September 29th, 2005 09:04 PM
Catching NULL values hasanali00 BOOK: ASP.NET Website Programming Problem-Design-Solution 1 July 1st, 2005 10:29 PM
How to Replace Null Values??? Varg_88 Classic ASP Basics 5 October 7th, 2004 02:28 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.