Solved

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

Posted on 2004-10-08
5
300 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks for the positive feedback!
I sometimes do a bit of private consulting.  My email address is in my profile.  
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Strange date stored 22 99
sum13 challenge 24 77
has22 challenge 11 70
FizzBuzz challenge 9 71
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now