T
tshad
The Crow said:you sure right about what properties are. but you should use (in my
opinion) decimal as data type of your property. if you will use object as
datatype, then dont bother with DBNull. just assign dbnull directly. my
intention using Decimal.MaxValue was because decimal type cant hold null
values...
But if I do that I won't be able to use the property directly
(myObject.Salary = mySalary.Text). Because mySalary.Text happens to be
blank, I end up with an error (as you can't assign a blank text field to a
decimal field).
you shouldnt assign a string to salary as database persistence will be a
disaster because your column type is decimal (or probably money in sql
server.).
I am not assigning a string to salary but converting the string to decimal
in the property methods.
have you inspected my decimalpicker example?
Yes, I assume you are talking about your nullHandler example..
That was where I got the idea of doing my class.
In your nullHandler, you pass an Object to the GetValueFromDbObject methods.
I call this from my Set/method and the overload is controlled by the
datatype of the private variable (salary).
Your handler works fine as long as you are not passing an empty textbox,
which was why I had to modify it. I wanted to handle the data regardless of
whether a textbox was being passed, decimal variable or decimal constant. I
also wanted to be able let the class handle conversions.
I didn't want to have to remember to use .ToString or .ToDecimal in my
code - I wanted the class to handle that.
My problem is that I needed to use 2 values MaxValue and MaxValue-1 to
handle the DBNull value as well as the Empty string value. If it came in as
an Empty string I would use that in my Get also (as a DBNull would cause an
error, if I was returning that to a textbox).
This may not work as cleanly as I would like as I cannot get the Get to work
correctly. This is because I have no way of knowing whether I am returning
the value to a Textbox or a decimal variable. I can't return an empty
string to a variable and I can't return a DBNull.Value to a textbox).
Tom