• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 372
  • Last Modified:

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 ;
}
0
Surfer
Asked:
Surfer
  • 3
  • 2
1 Solution
 
DanRollinsCommented:
From this..
    rs.m_MyDouble
I assume that you are using CRecordset class object.  For numeric values, a NULL field in the database returns a screwball value like 0x12346789 -- I think this takes place in the CRecordset DDX process -- probably in RFX_Double().

Try using the IsFieldNull() function.  For instance:

    if ( IsFieldNull( &rs.m_MyDouble ) ) {
         ... the field is NULL (in the database sense: it has not be set to a value)
    }

-- Dan
0
 
SurferAuthor Commented:
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?
0
 
DanRollinsCommented:
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
0
 
SurferAuthor Commented:
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 ?
0
 
DanRollinsCommented:
Thanks for the positive feedback!
I sometimes do a bit of private consulting.  My email address is in my profile.  
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now