Null handling from a database query

  • Thread starter Thread starter Dan
  • Start date Start date
D

Dan

I have created a class with a method that reads from a SQL
database in order to populate members within that class. I
am using the SQLParameter class to process the parameters
resulting from the called stored procedure. Some of the
columns in the database allow nulls.

Here are a couple of the lines of code:

_myDate = (DateTime) command.Parameters["@my_date"].Value;
_count = command.Parameteres["@count"].Value;

My question is, is there a way to assign these possibly
null values to member variables without conditionally
testing whether or not the source is equal to null?

Thanks
 
I'm not sure what the date field should contain in case of null.

I like to do it on server-side:

for numbers:

ISNULL(MyNumber, 0)

for text:

ISNULL(MyString, '')
 
I would think about using SqlTypes...

Imports System.Data.SqlTypes

dim _myDate as SqlDateTime

_myDate = new SqlDateTime(command.parameters["@my_date"].Value);
 
Back
Top