Null handling from a database query

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

Ivan Demkovitch

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, '')
 
D

Doug Swanson

I would think about using SqlTypes...

Imports System.Data.SqlTypes

dim _myDate as SqlDateTime

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top