Link to home
Start Free TrialLog in
Avatar of kingservant
kingservantFlag for United States of America

asked on

How do you evaluate for NULL in ADO

I am trying to retrieve the value of a field that could be NULL.  I do this by using the following call:

strcpy(string, (LPCSTR)(_bstr_t)pFields->GetItem(vtIndex)->Value);

My database allows fields to be NULL.  Therefore, unless I want to keep receiving an exception error, I need to check the value for NULL.  Problem is, I'm not sure how to do that.  

Can someone help?!?
Avatar of Chizl
Chizl
Flag of United States of America image

Looks like your doing a RecordSet loop.  I would suggest you try GetRows(-1) to get your data returned into a _variant_t array, then close your recordset.   Then your eval will be much simpler and your process time will be much faster.

I have an example of this up on:
http://www.chizl.com/dev/c++/

Let me know if you have any questions about it.
BTW.. About the NULL, try catch() is the solution, but still suggest using GetRows(-1).   The -1 is for all records.
ASKER CERTIFIED SOLUTION
Avatar of Chizl
Chizl
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 kingservant

ASKER

Out of all the people who have responded to me on this forum, you have got to be the best!  Thanks for your response, complete with code examples and links, I love it.  I'll grade your answer tomorrow after I get to work.  BTW, do you have any other suggestions I could make to my code to make it more efficient?
Thanks for you response.  You're the best!
Thanks for you response.  You're the best!