?
Solved

CRecordset and CLongBinary (BLOB problem)

Posted on 1998-08-20
3
Medium Priority
?
1,220 Views
Last Modified: 2013-11-20
How do I store a blob through ODBC !
I got a CLongBinary object in a derived CRecordset and a BMP-file on disk.
1. - How do I load the BMP into the CLongBinary-object
2. - Does the CLongBinary automaticly get into the base on CRecordset.update() ?
Codesample please !!

0
Comment
Question by:Jeb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Accepted Solution

by:
MURALI_YAKKALI earned 240 total points
ID: 1321090
First you have to copy BMP file into CLongBinary object.
you can do this by
Here
 strFileName = BMP file name
 BinaryObj   =  long binary object

:: int  LoadBlobFromFile(CString& strFileName,CLongBinary* BinaryObj)
{

      CFile            blobFile(NULL);
      DWORD            FileLth;
      void*            lVoidPtr = NULL;

      if(blobFile.Open(strFileName,CFile::typeBinary | CFile::modeRead))
      {

            FileLth = blobFile.GetLength();
      
            BinaryObj->m_hData = GlobalAlloc(0,FileLth);
            BinaryObj->m_dwDataLength = FileLth;

            lVoidPtr = GlobalLock(BinaryObj->m_hData);
            DWORD lTemp = blobFile.ReadHuge(lVoidPtr,FileLth);
            GlobalUnlock(BinaryObj->m_hData);
            strFileName = blobFile.GetFileName();
            blobFile.Close();
            return SUCCESS;

      }
      else
            return FAILURE;

} // End of LoadBlobFromFile

After loading bmp into longbinary you have to store this into database
You can do this by
DWORD i,dwSize;
BYTE* lpdstbyte = NULL;
BYTE* lpsrcbyte = NULL;
int :: AddnewRecord(CLongBinary* pDataObj)
{
      try
      {
            if(!IsOpen())
              Open();
            AddNew();  

      if(pDataObj.m_hData && ::GlobalSize(m_DataObj.m_hData))
      {
            ::GlobalFree(m_DataObj.m_hData);
            m_DataObj.m_hData = NULL;
            m_DataObj.m_dwDataLength = 0;
      }

      dwSize = pDataObj.m_dwDataLength;
      m_DataObj.m_hData  = GlobalAlloc(0,dwSize);

      lpdstbyte = (BYTE*)GlobalLock(m_DataObj.m_hData);
      if(lpdstbyte == NULL)
            return *this;

      lpsrcbyte = (BYTE*)GlobalLock(pDataObj.m_hData);
      if(lpsrcbyte == NULL)
      {
            GlobalUnlock(m_DataObj.m_hData);
                return;
      }

      for(i=0; i< dwSize; i++)
      {
            lpdstbyte[i] = lpsrcbyte[i];
      }

      m_DataObj.m_dwDataLength   =  dwSize;

      GlobalUnlock(m_DataObj.m_hData);
      GlobalUnlock(pDataObj.m_hData);
                                       
        SetFieldDirty(&m_DataObj,TRUE);                                    
        SetFieldNull(&m_DataObj,FALSE);      
      Update();
      Close();
        return SUCCESS;

      }
      catch(CDBException* fe)
      {
            return FAILURE;
      }

}

This is complete code for storing blob intodatabase.
Hope this will help U!!


0
 

Author Comment

by:Jeb
ID: 1321091
You saved my holiday :)
0
 

Author Comment

by:Jeb
ID: 1321092
It should have been 80 points instead of 8 !!  sorry
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question