Re: Accessing binary field in a Microsoft Access database table

Tech-Archive recommends: Fix windows errors by optimizing your registry



I need to retrieve data from a binary field in a Microsoft Access database
table. Below is a segment of my failed attempt at doing this in C++. I
hope
you can suggest a solution to my dilemma.

Thanks,
Miguel


ADODB::FieldPtr pField = rec->Fields->GetItem("SHAPE");
_variant_t vField;
vField.Clear( );
vField = pField->Value;

This can be just

_variant_t vField = rec->Fields->GetItem("SHAPE")->Value;

long *shape; // my hope is that this variable will point
to
the contents fo the field. I know the format of the data.
if (vField.vt != VT_NULL) {
shape = pField->Value; // the compiler rejects this statement:
mismatched data types.

Which it would do. Value is not a pointer.

There is absolutely no guarantee that the variant contains a long.
The variants should be used _BY VALUE_ not by pointer.
So I would do

long shape = (long)pField->Value;

as the variant will coerce if it can into the correct value.
And if you need a pointer (or better still reference), then construct a
pointer (reference) to the variant, not a long.

So

_variant_t *pvField = &(rec->Fields->GetItem("SHAPE"));
_variant_t &vField = rec->Fields->GetItem("SHAPE");

Stephen Howe


.



Relevant Pages