Re: Accessing binary field in a Microsoft Access database table
- From: "Stephen Howe" <stephenPOINThoweATtns-globalPOINTcom>
- Date: Thu, 9 Aug 2007 16:15:01 +0100
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
.
- Prev by Date: Re: MDAC Converting Dataset to XML
- Next by Date: Re: Accessing binary field in a Microsoft Access database table
- Previous by thread: connection string format
- Next by thread: Re: Accessing binary field in a Microsoft Access database table
- Index(es):
Relevant Pages
|