Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics 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
  #1 (permalink)  
Old November 20th, 2006, 10:23 AM
Authorized User
 
Join Date: Jan 2004
Location: , , .
Posts: 30
Thanks: 1
Thanked 0 Times in 0 Posts
Default Convert DBNull to String

In SQL is have a column with data and Null values. The Null values need to be converted to string. Thus far nothing I have tried works.
The results are sent to a datagrid.
My code snipet:
DataAccessLayer:
While reader.Read()
   colEmployees.Add((New Staff( _
   (reader("Cars"))
End While

BusinessLayer:
        Public Property Cars() As String
            Get
                Return m_Car
            End Get
            Set(ByVal value As String)
                value = System.Convert.ToString("m_Car")
            End Set
        End Property


  #2 (permalink)  
Old November 21st, 2006, 02:16 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Take a look at the IsDBNull method of the data readers: http://msdn2.microsoft.com/en-US/lib....isdbnull.aspx

It allows you to check whether a column is null *before* you assign it to the string. Then you got the chance to assign something different to the string instead.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.


Similar Threads
Thread Thread Starter Forum Replies Last Post
convert to string prafullaborade XML 7 May 29th, 2008 02:59 PM
Conversion from type 'DBNull' to type 'String' is GailCG ASP.NET 2.0 Basics 5 February 22nd, 2007 03:12 PM
String="" convert to DBNull bekim ASP.NET 1.0 and 1.1 Basics 1 February 28th, 2006 01:28 AM
setting DBNull to a string in a dataset at runtime texasraven Classic ASP Professional 2 September 3rd, 2003 04:28 PM





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