Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

empty string with ado

Status
Not open for further replies.

StefanoCarniel

Programmer
Apr 29, 2005
15
0
0
IT
Hello, I'm trying to read the value of the field PostalCode from an Access database using ado with the following sintax:

CString buff;

buff = pRecordsetAccess->Fields->GetItem ("PostalCode")->Value.bstrVal;

but if the field is empty (NULL value), I get an access violation error. I tried to use other sintax, like

....->Value.bVal;

in this case I do not get any error, but in buff I find a strange character and not an empty string. How can I manage this situation?

Thank you
 
That is because a NULL value in fact is not an empty string. You should first check for a NULL value and then try to assign it to your string buffer.

Greetings,
Rick
 
Maybe even better; have the query return an empty string in case of a NULL value. Don;t know if the same syntax can be used in an acces database, but somthing like ISNULL(PostalCode, '')...

Greetings,
Rick
 
Try this approach in Access ADO apps:
Code:
inline bool isNull(const _variant_t& v)
{
       return v.vt == VT_NULL;
}
inline bool isNull(const ADODB::FieldPtr& p)
{
     return isNull(p->Value);//p->Value.vt == VT_NULL;
}
It works.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top