Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 2 of 2 total
Thread Casting vs. String.Format
Wed, Jun 3 2009 4:44 PMPermanent Link

David Loving
MS VS 2008 C# code.  ElevateDB version 2.2.13.0

I use DBDataReader to access a row of data from an ElevateDB database table.

For most field datatypes, I can simply cast the returned object to the dataype I need such as (double)reader["fieldname"] or (int)reader["fieldname"]

Strings don't work all the time.  (string)reader["fieldname"] will error if the value in the table is null instead of an empty string.

string.Format("{0}", reader["fieldname"]) will work with both null and empty strings in the table and return an empty string.

Is this a bug in casting vs. formatting the return object from the ElevateDB library or another quirk in MS C# that makes ya go hmm...?
Fri, Jun 5 2009 3:50 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

David,

<< Strings don't work all the time.  (string)reader["fieldname"] will error
if the value in the table is null instead of an empty string. >>

But you don't get the error if an integer column is NULL ?  Both should
return an instance from  System.Convert.DbNull that represents a NULL column
value.

--
Tim Young
Elevate Software
www.elevatesoft.com

Image