Problem extracting empty strings from MSAccess
i am using ADO to extract records from MSAccess Tables. essentially one submits an SQL string and a record set pointer is returned. one
then loops with the pointer, movint the contents of a selected record
into a variant_t datatype and then extracting the relevant data.
here is typical code that extracts an MSAccess field name StringVar and
attempts to place it in CString variable of the same name:
variant_t RetVal;
for (i = 0;i<n;.i ++){
...RetVal = RecordsetPtr->Fields->Item["StringVar"]->Value;
...(p + i)->StringVar = RetVal.bstrVal;
}
The problem is that when there is a string of length 0 in a field
of the MSAccess record an exception is thrown. =THe code works fine
when ever there is text of any length > 0 in the MSAccess table.
is there a "trick" to populating the CString var with "" when this is the
case?
appreciate any insight.
thanks - j
# 1 Re: Problem extracting empty strings from MSAccess
In VB there is a function to check null values.
If IsNull(Myrs!['Field']) then
But I'm not sure if there is something like that for the language you are using.
BTW:
With Access you use the isnull function, and make null values return 0
SELECT Field1, Field2, IIF(IsNull(Field3),'0',Field3) as [MyField3]
FROM Table1
Hope that helps!
# 2 Re: Problem extracting empty strings from MSAccess
this is part of my frustration. the value residing in the bstrval component
of the RetVal is '0xcccccccc' but when this is compared to NULL it fails.
1. is '0xcccccccc' == NULL?
2. if not, what is the expression to compare '0xccccc' with
RetVal.bstrVal?
3. if ( RetVal.bstrVal == '0xcccccccc' ){ does not compile - too many chars in constant
i have a hard time believing there is no way to get an empty string out
of MSAccess.
appreciate any insight.
j
# 4 Re: Problem extracting empty strings from MSAccess
Jim couldn't you just do the IIF statement in your query and have it give a unique value out to show it is null
SELECT Field1, Field2, IIF(IsNull(Field3),'UniqueValue',Field3) as [MyField3]
FROM Table1
As far as your others questions go I think they'd be best suited in the programming language forum. Is that C++, Java?
# 5 Re: Problem extracting empty strings from MSAccess
the winner is check the vt member of the variant_t to see if it is
VT_NULL eg :
RetVal = RecordsetPtr->Fields->Item["SomeAccessTextField"]->Value;
if (RetVal.vt != VT_NULL ){ // CString
(List.p + i)->s1 = RetVal.bstr;
}
else{
(List.p + i)->s1 = "";
}