Solved

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

Posted on 2004-10-08
5
306 Views
Last Modified: 2013-11-20
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
Comment
Question by:Surfer
  • 3
  • 2
5 Comments
 
LVL 49

Accepted Solution

by:
DanRollins earned 500 total points
ID: 12268204
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
 

Author Comment

by:Surfer
ID: 12268982
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 12269489
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
 

Author Comment

by:Surfer
ID: 12272522
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 12274666
Thanks for the positive feedback!
I sometimes do a bit of private consulting.  My email address is in my profile.  
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Login Script to Copy Folders 12 36
Excel Use VBA to get user's Mac Address for their computer 5 181
has22 challenge 11 96
wait notify demo infinite loop 3 114
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

822 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question