Click to See Complete Forum and Search --> : How can store a BitMap file in a DB using ODBC ?


Tamanna farahani
May 8th, 1999, 12:25 AM
Hi
How can store a bitmap file in a Db by using ODBC ?
I use CLONGBINARY type for bitmapfile and my code is here :
/****/
BOOL CPicture_Dialog::Onsave_In_DB(CString blobfileName,HGLOBAL *phDIB)
{
BITMAPFILEHEADER bmfHeader;
CFile cFile(blobfileName, CFile::modeRead) ;
int nFileSize = cFile.GetLength() ;
int HeaderSize=sizeof(bmfHeader);
HGLOBAL hNewDBImage = ::GlobalAlloc(GHND, nFileSize) ;

if(hNewDBImage==0)
return FALSE;

if (cFile.Read((LPSTR)&bmfHeader,HeaderSize) != HeaderSize)
return FALSE;

if (bmfHeader.bfType != ((WORD) ('M' << 8) | 'B'))
return FALSE;
// Read the remainder of bitmap file
if((cFile.ReadHuge( (LPSTR)hNewDBImage , nFileSize-HeaderSize )) != nFileSize-HaderSize )
return FALSE;
/ /**** here is my problem !
Pic_bmpSet.AddNew() ;
Pic_bmpSet.m_BITMAP_FILE.m_hData = hNewDBImage ;
// Pic_bmpSet.m_BITMAP_FILE.m_dwDataLength = nFileSize ;
Pic_bmpSet.m_NUM = 1;
Pic_bmpSet.Update();

::GlobalUnlock(hNewDBImage) ;
::GlobalFree(hNewDBImage) ;
*phDIB = hNewDBImage;
return TRUE;
}
but in addnew section , only image field is not added to DB and in trace the size is 0 .
please send me your solution .
thanks
Tamanna

May 8th, 1999, 08:40 AM
There is a post in the database section of this site which does just what you desire, take a look at that.