I would like to put a binary file in varbinary(MAX) column using _RecordsetPtr in a vc++ application.I am sure that lot of people have done this before. But I am new to database programming. Help is urgently needed ...Thanks in advance.
A:
I found this example :
while(!rst->EndOfFile)
{
int shotid = rst->Fields->Item["shot_id"]->Value;
int shotPoint = rst->Fields->Item["shot_num"]->Value;
int length = rst->Fields->Item["length"]->Value;
--- I initialized tha variant and copied the variant into local memory. After that I accessed the SafeArray.
VariantInit(&varBlob);
//varBlob = rst->Fields->Item["data"]->GetChunk((long) MAX_HYDRO_SIZE);
varBlob = rst->Fields->Item["data"]->GetValue();
unsigned char* pData;
unsigned char data[MAX_HYDRO_SIZE];
int blobLength;
if (varBlob.vt == (VT_ARRAY | VT_UI1))
{
SafeArrayAccessData(varBlob.parray,(void **) &pData);
blobLength = varBlob.parray->rgsabound[0].cElements;
TRACE(" length %d : blobLength %d \n",length*4, blobLength);
if (length*4 > blobLength)
AfxMessageBox("Blob Short of Data");
memcpy(&data,pData,blobLength);
SafeArrayUnaccessData(varBlob.parray);
}
else
AfxMessageBox("BLOB returned wrong type");
on http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/Q_21296032.html
Preet Sangha
2010-05-11 07:12:20
Thank Preet but I could not use the code as I am not able to write the file in the varbinary(MAX) column of the database at the very first place. Once again thank you very much as you are trying to help me.Have a nice day.
Feroz Khan
2010-05-11 11:28:21