Solved

How to Store and retrieve BMP's and JPG's into database recordset

Posted on 1998-09-01
4
713 Views
Last Modified: 2008-02-01
We need to store some large binary data into database . It may be of bitmap or jPEG or text file.
How to store them in database. I think we can make use of " CLongBinary" and corresponding RFX_LongBinary for CRecordset classes .
We are not able to store data and retrieve data from table.
Can anybody suggest the way of reading and writing bitmap file from database , using CLongBinary and RFX_LongBinary or any other way how ro deal witrh BLOB.
The database may be any type Oracle or MSAccess etc. It should be database indipendent.
0
Comment
Question by:rsquek
  • 2
4 Comments
 

Author Comment

by:rsquek
ID: 1171821
Adjusted points to 200
0
 
LVL 2

Expert Comment

by:duneram
ID: 1171822
blobs are definitely the way to go. I'll look into it
0
 
LVL 2

Accepted Solution

by:
milenvk earned 200 total points
ID: 1171823
Well, here's the deal. You better use CByteArray and RFX_Binary, since they don't have boundary limit like CLongBinary and RFX_LongBinary. The way to go is:

// theByteArray is the array that is binded to the BLOB using RFX_Binary
// theImageByteSize is the size of the file in bytes
theByteArray.SetSize(theImageByteSize)
BYTE* pb = theByteArray.GetData();
// pbTheImageDataFromFile is the memory where you copied the data from the file
memcpy(pb, pbTheImageDataFromFile, theImageByteSize);
// rs is your recordset - you have to have called AddNew or Edit before that
rs.Update();

That's the way to put the data in the DB...
To get the data (assuming the recordset has positioned its cursor to the record of interest):

BYTE *pb = theByteArray.GetData();
int size = theByteArray.GetSize();

// Now *pb points to the memory with the data from the picture file
// and size is the size of the picture file
0
 
LVL 2

Expert Comment

by:milenvk
ID: 1171824
Opps... I forgot the binding...
Here is the recordset's DoFieldExchange() part:

void CMyRecordset::DoFieldExchange( CFieldExchange* pFX )
{
  //...
  RFX_Binary(pFX, "TheColumnName", theByteArray);
  //...
}

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

896 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now