SafeDataReader and DBNull integers

SafeDataReader and DBNull integers

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


Manny posted on Thursday, November 20, 2008

I'm currently working on a project (CSLA 3.0) that has some integer fields in it's database that can be Null. However, the SafeDataReader class always returns a 0 instead of the needed Null. This happens in both creating and retrieving a new BO, as described in the SafeDataReader class' comments. However, my need is to retrieve the actual Null values and write them back to the database when needed.

Is there a way to go about this without having to customize the SafeDataReader?

tetranz replied on Thursday, November 20, 2008

You need to use GetValue and cast it.

int? x = (int?) dr.GetValue("MyField");

Copyright (c) Marimer LLC