Link to home
Start Free TrialLog in
Avatar of Surfer
Surfer

asked on

URGENT!! DAO, VC6.0 and reading an empty double field.

Using Access 97, sometime ago, I created a database.mdb file with various fields.  Using the Designer feature in Access, I created a field called, MyDoubles.  I gave them the double parameter settings in Access and away I went.  Up until know, I have not had to read or write to the MyDouble fields.  However, things have changed and I need to read or write to this field.  Looking at the fields with Access I see they are blank. ( Nothing appears visible in the MyDouble field ) However if I read the blank fields, I get something like:
double m_MyDouble = -9.1229998193784e+019
What gives.  First, I thought the field would be empty or NULL, then to find out it has this value that does not appear in Access when viewing the MyDoubles filed?

COleVariant vMyDouble(rs.m_MyDouble ) ;
double db = vMyDouble.dblVal ;
if ( vMyDouble.vt == VT_EMPTY || vMyDouble.vt == VT_NULL ) {
m_MyDouble = 0.100 ;// field was 'blank' so use this vaule
}
else {
m_MyDouble = vMyDouble.dblVal ;
}
ASKER CERTIFIED SOLUTION
Avatar of DanRollins
DanRollins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Surfer
Surfer

ASKER

Thanks!  IsFieldNull was the answer!  I can not believe I did not find IsFieldNull. Do you know way
COleVariant vMyDouble(rs.m_MyDouble ) ;
double db = vMyDouble.dblVal ;
if ( vMyDouble.vt == VT_EMPTY || vMyDouble.vt == VT_NULL ) {
}
did not work?
I don't know for certain.  But I do know that for integer data fields, MFC places a special  uncommon value in them if the database says they are NULL.

Creating a COleVariant from that value in the CRecordset member field does not take this into consideration... it just treats that special uncommon value as a numeric quantity.

In database theory and practice, this distinction between 0 (zero) and NULL is very important.  A value of
      "zero, a certain quantity... more than -1, but less than 1"  
is very different from a value of
      "NULL, I don't know, nobody ever set this to anything"  
so that is why MFC CRecordset objects -- and all database data handling systems -- provide special handling.

It is awkward, but there are several things you can do:  
When designing a database, you can set the field so that it does not allow NULL values.  
Or you can set a default so that if the field is never set to anything, it will have that specific value.  
Or you can store numeric values as strings of digits and convert them as needed (when the string is "", then no value has been assigned to it).  
Or you can always use IsFieldNull() before using the member variable in the CRecordset.

-- Dan
Avatar of Surfer

ASKER

Thanks for all the great info! You comments are alway helpful.   Do you have a website?  Do you do private consulting as a designer / coder ?
Thanks for the positive feedback!
I sometimes do a bit of private consulting.  My email address is in my profile.