?
Solved

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

Posted on 2004-10-08
5
Medium Priority
?
328 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 49

Accepted Solution

by:
DanRollins earned 2000 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

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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…
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.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month7 days, 21 hours left to enroll

765 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