CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 1999
    Posts
    4

    How can store a BitMap file in a DB using ODBC ?

    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


  2. #2
    Guest

    Re: How can store a BitMap file in a DB using ODBC ?

    There is a post in the database section of this site which does just what you desire, take a look at that.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured