SafeDataReader returning null values?

Old forum URL: forums.lhotka.net/forums/t/12511.aspx

GaryG posted on Wednesday, March 19, 2014

I had assumed that SafeDataReader would convert any null strings coming from SQL Server into String.Empty.

But after finding some app exceptions logged, I have confirmed that null values from the database are being set to Nothing (vb.net) in their properties. I don't want to have to deal with null/Nothing in string properties.

Am I doing something wrong?

The code I am using was generated by CodeSmith, using encapsulated implementation. It uses a SafeDataReader, and in this case it passes it to a Map routine.

Am I doing something wrong? I'd hate to have to write a bunch of code to check for null values, and convert them to empty strings.

Thanks.

FWIW, I'm a longtime user of CSLA (since VB6 days). Not on every project, but on quite a few, in different industries. It's a great tool.

JonnyBee replied on Wednesday, March 19, 2014

Hi,

I would like to see more of your code and how you use SafeDataReader.

If you use reader["LongDescription"] - the method returns an object and YOUR CODE is responsible for conversion and/or null check.If you use reader.GetString("LongDescription") - the method knows which type to return and will always return a string value (assuming the underlying DataReader correctly identifies the value as null, ie IsDBNull returns true).