By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,930 Members | 1,413 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,930 IT Pros & Developers. It's quick & easy.

How to handle nulls in a construcor

P: n/a
Hi, Im real new at this so be gentle. I want to create a customer
object based on the results of an sql query to the customers table, ie
one object per row, and then add each of these objects to an arraylist
and then on to some datbinding in a listbox. Therefore, for each row
sent back by the datareader, I try to create the new customer object
and pass all the data in the row as part of the constructor. But, I
declared the data fields in the customer class to be the same data type
as those in the database but null causes a problem. To get round the
problem, I just made addtional New constuctors for each column which
may have nulls and then set the datfields to empty strings inside the
constructor and thus not pass the null data at all from the datreader
row. But that is a lot of kludge to test for null before the call to
the constructor so that i call the right constructor. i tried to have
constructors which accepts nulls as arguments and then set the private
data fields to empty strings from there but ran in to cast problems
*(esp with strict ON) in the call to the constructor.
What is the right way to create objects whose private data fields are
of one data type , but whose arguments might be null when they are
instantiated and how should null arguments be specified.

Nov 21 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.