Nullvalued doubles in a strong typed dataset

  • Thread starter Thread starter Thomas Schissler
  • Start date Start date
T

Thomas Schissler

I have a strong typed dataset with some double values. In my database, from
where I fill the dataset, I have numbers for these doubles, but they can
also bee empty (NULL). I need this to know if the user has typed in 0 or
hase typed in nothing.

If I set the nullvalue for the doubles in my dataset to (NULL), I get an
exception. How can I pass the System.DBNULL value from my database to my
doubles?

Thanks
Thomas
 
Thomas,

If the element is nillable, the row class built into the strongly typed
dataset class should expose a Set<element name>Null method that you can use
to specify a null value when adding or modifying a row.

HTH,
Nicole
 
Hi Nicole,

thanks for your answer.
OK, that's a good way to set the double variable to null. But my problem is
a litte bit more difficult. Maybe I'm blind and I can't see the solution.

The problem is that if I read a a System.DBNULL value from the database, I
can set my double to 0, but I can't set it to NULL, because this is invalid
for doubles. If I then put the value to a input element like a textbox, the
user cannt decide wheter the field in the database was empty or 0. And if I
put it back to the database I don't know if I should write 0 or NULL because
the double value is 0.

I tried to handle this with double.NaN. So if the value in the Database ist
empty I set my double to double.NaN and so I can handle it also back. The
problem is that the typed dataset does not accept double.NaN as a nullvalue.

To make the upper problem more difficult, I'd like to work with databinding.
So the dataset should be used as a datasourece for a editable datagrid.

Do you have a suggestion how to read System.DBNULL from a database to a
double value or do you know a workaround to handle the upper problems? How
do you do such things? I can't imagine I'm the first dealing with these
topics.

Thanks
Thomas
 
Thomas Schissler said:
The problem is that if I read a a System.DBNULL value from the database, I
can set my double to 0, but I can't set it to NULL, because this is invalid
for doubles.

What is "my double" in this sentence?

If I then put the value to a input element like a textbox, the
user cannt decide wheter the field in the database was empty or 0.

In which case, you'll need to use the textbox's Text property, which is a
string. You can use an empty string instead of 0 to represent nulls.

And if I
put it back to the database I don't know if I should write 0 or NULL because
the double value is 0.

If textbox's Text property returns an empty string, presumably a null should
be inferred.


To make the upper problem more difficult, I'd like to work with databinding.
So the dataset should be used as a datasourece for a editable datagrid.

System.Web.UI.WebControls.DataGrid or System.Windows.Forms.DataGrid or...?
 
Hi Nicole,

find some comments about your questions below. If you think you can help me
bettwer with a more detailed description of the problem and some sample
code, please let me know.

Thanks
Thomas

Nicole Calinoiu said:
What is "my double" in this sentence?
This is the double value in my typed dataset.
In which case, you'll need to use the textbox's Text property, which is a
string. You can use an empty string instead of 0 to represent nulls.



If textbox's Text property returns an empty string, presumably a null should
be inferred.
But I can't access my textbox value property directly. The value of the
textbox is transfered to my double value in my typed dataset and the dataset
is used for writing to the database. So how do I set the value ob my double
in the typed dataset? The way I tried to set it to Double.NaN whren the
Textbox is empty.
System.Web.UI.WebControls.DataGrid or System.Windows.Forms.DataGrid or...?
System.Web.UI.WebControls.DataGrid !
 
Thomas,

I suspect that the problem lies with the approach you are using for your
databinding. The null problem is completely avoidable since you can work
against the textbox in such a way as to control the interpretation of empty
string values. It would help to see your problem code, but please don't
attach it to a newgroup posting. Do you have a location at which you could
post it for download as, say, a zip file?

Nicole
 
Back
Top