Hwo to Store and Retrive BMP's and JPG's into Database thr Recordset...
Posted on 1998-05-10
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 data base.I think we can make use of "CLong Binary" and corresponding
"RFX_LongBinary " for CRecordset classes.We are not able to store data and retrive data from table.
Can any body suggest the way of Reading and writing bitmap file from database ,using CLong
binary and RFX_LongBinary. Or any Othere way how to ,deal with BLOB .
The database may be any type oracle or MSAccess etc.It should be database independent.
Here is Sample Code... which we wrote...
strFile.Open("C:\\VC++\\Mahesh.bmp",CFile::typeBinary | CFile::modeRead);
FileLth = strFile.GetLength();
byt = new BYTE[FileLth];
DWORD ltemp = strFile.ReadHuge(byt,FileLth);
//Here the length is incresing by 1 byte ,i did't got why it is incresed by 1 byte //after
calling this function.
blobObj.SetBlob(&ByteObj, nLen); // This is function of class which is derived
Code for the SetBlob function.
m_Size = pBlob->GetSize();
m_Size = m_BlobValue.GetSize();
m_BlobID = nID;
AfxMessageBox("Blob is Stored into Database");
I Checked for Size of CByteArray before storing ,Before copying into pBlob it is one less than
,after coping from ByteOb to pBlob.
It is storing into database.Presently we are using MS-Access,We are using field type is Oleobject
.If We double click onthe field value,it can't be opened by Paintbrush or with some other.Its saying
oleserver could not found.restart Ms-access and set the oleserver.I did't know whether image is
properly stored or not.
While retiving the blob the function is
int CBlobTest :: GetBlob(CByteArray* pBlob,long& nID)
m_strFilter = "BlobID = 3";
FileLth = m_BlobValue.GetSize();
for(int i = 1 ; i < FileLth ;i++)
byt = m_BlobValue.GetAt(i);
byt = NULL;
AfxMessageBox("Field is Loaded from database");
It is writing some bytes into file.But i could 't open it with Paintbursh or lview or someother.I did't
Got what is happing there.It seems corretly writing but ,could''nt get sloved.Can U Please help
Can u Please give the complete source code for this.