473,394 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Null handling from a database query

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
Nov 17 '05 #1
2 913
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, '')
"Dan" <an*******@discussions.microsoft.com> wrote in message
news:08****************************@phx.gbl...
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

Nov 17 '05 #2
I would think about using SqlTypes...

Imports System.Data.SqlTypes

dim _myDate as SqlDateTime

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

"Dan" <an*******@discussions.microsoft.com> wrote in message
news:08****************************@phx.gbl...
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

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Kevin Frey | last post by:
Hello, I have a table which contains some nullable columns. I want to write a single query, which can be prepared (ie. prepared statement), that can handle null or non-null values for the where...
4
by: Brendan McLoughlin | last post by:
Hi, I am looking for opinions and alternatives for handling null values in a data object which reads a record from a database table. This object will have properties which will be populated...
6
by: AAVF | last post by:
Hi We have a problem with a query. An Access database links via ODBC to a UNIX server. To speed things, we use the ODBC to load the relevant tables to the local PC that runs Access so that...
2
by: Steve Jorgensen | last post by:
When writing VB or VBA code that works with databases or other external libraries that cannot be trusted to automatically do the right thing when references to their objects are arbitrarily...
4
by: James Fisher | last post by:
How are people handling NULL values for value types. Descriptions of problem Say you have a typical method with the signature: public int InsertPerson(string firstName, string lastName, int...
2
by: ILCSP | last post by:
Hello, I'm in the process of changing our 'normal' Access 2000 update queries to Update Pass Through Queries. We have a SQL server 2000 database and we're using an Access 2000 database as our...
17
by: Mark A | last post by:
DB2 8.2 for Linux, FP 10 (also performs the same on DB2 8.2 for Windoes, FP 11). Using the SAMPLE database, tables EMP and EMLOYEE. In the followng stored procedure, 2 NULL columns (COMM) are...
5
by: AAJ | last post by:
Hi Does anyone know of any good publically available set of standards for managing dates when dealing with a database server (in my case SQL Server 2000 and c# VS2005). At the moment, if I...
3
ADezii
by: ADezii | last post by:
Null as it relates to database development is one of life's little mysteries and a topic of total confusion for novices who venture out into the database world. A Null Value is not zero (0), a zero...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.