Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Inserting images into Access tables

0 views
Skip to first unread message

Andre Uchoa

unread,
Aug 10, 2001, 2:39:33 PM8/10/01
to
I'm using ADO to connect to a .mdb and need to insert Images into a table.
Any ideas?

Thanx in advance.
André Uchôa


Brett Morris

unread,
Aug 10, 2001, 3:24:00 PM8/10/01
to
Using C++ or VB? I've been working on retrieving images
(binary data) from Access and SQL Server using ADO in C++.
Here is some sample code of what I've been doing in C++ to
retrieve the images.

_variant_t vFieldData = pRecordset->Fields->GetItem(
fieldName )->Value;
// binary data
if (vFieldData.vt == (VT_ARRAY | VT_UI1))
{
BYTE* pBytes = new BYTE[vFieldData.parray->rgsabound
[0].cElements];
void HUGEP *pvData;
HRESULT hr = SafeArrayAccessData(v.parray, &pvData);
//Keeping bytes in original order, with most
significant byte first
for (int i=0; i < vFieldData.parray->rgsabound
[0].cElements; i++)
{
// CLUDGE: skip to 78 position in array
pBytes[i] = ((BYTE*) (pvData)) [i+78];
}
hr = SafeArrayUnaccessData(vFieldData.parray);
// Output resulting bytes to a file for viewing.
ofstream outFile("d:\\temp\\debug.bmp", ios::out);
for (int i=0; i < size; i++)
{
outFile << pBytes[i];
}
outFile.close();
delete [] pBytes;
}

If you are using C++ then you will probably have to do
something similar when inserting binary data such as an
image. I haven't attempted inserting binary data, since I
primarily use ADO to access data from pre-populated
databases. It is difficult to find documentation on
inserting and retrieving binary data using ADO. I
basically figured this much out through trial and error.

There is one problem I'm having though. The image is not
in the correct format if I don't start at the 78th bit in
the safe array returned from the variant. There is some
data at the beginning of the array that gets outputted to
the file and is unrecognized by the viewer (IE, paint
shop, etc.). When I remove this data I can display the
file correctly in IE. If you or anyone else can show me a
better way of accessing binary data from the field value I
would really appreciate it :-)? My method only works for
images. Word docs, excel docs, wave files, etc. do not
output correctly.

>.
>

0 new messages