BLOB field to StdPicture WITHOUT temp file and WITHOUT thirt-party libraries

Hi, I need some help with BLOB -> StdPicture conversion.
   I store JPG file data(student pictures) in the BLOB field in SQL Server. I read file using Stream object and then save it to the field. So, I need to know how to load image data from SQL Server BLOB field to PictureBox directly (NO temporary files). I've tried the trick with DataSource and DataField properties of PictureBox. It was working but now it shows me the error saying Class Not registered or something like that, so now i dont really trust it. If you have any ideas how to fix that, that would help me a little, but its NOT really what I am looking for.
  I am NOT interested in temporary files, these suggestions are everywhere on the web. And please, no third-party libraries (unless they include VB source code).

Thanks everyone, your help will be appreciated. Thanks again!!
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Please post your code and error.
Pls try the code from the page below :
Save/Retrieve Image From SQL Server Database Using Ado 2.5 Stream Object
You can download a sample of this at :

It contains a VB5 project for doing this as well as a tiny access database (pictures.mdb). Put the database file in c:\My Documents
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

aleksey_nycAuthor Commented:

Here is the code i have...

Dim objRS As New ADODB.Recordset
objRS.Open "SELECT ImageData FROM tblPhoto WHERE ID=1, g_objConnection, adOpenForwardOnly, adLockReadOnly
If Not objRS.EOF Then
   Set PictureObject.DataSource = objRS
   PictureObject.DataField = "ImageData"
   EmployeePicture = objRS("OriginalFileName") & ""
End If
Set objRS = Nothing

error happens on line - Set PictureObject.DataSource = objRS

and error I am getting is...

Run time error '713':
Class not registered.
Looking for object with CLSID:{59245250-7A2F......ED}

I would assume I am having some configuration/system problems.
aleksey_nycAuthor Commented:
freevbcode you posted doesn't answer my question. It uses file to temporarily store data. Please, pay attention to what I have said... <b>NO TEMPORARY FILES<b>. I don't want to create any files on user's computer (even temporarily).

ya,i know that after i chk that project,sorry.
aleksey_nycAuthor Commented:
Sorry, last link doesnt help me either, I know how to save file into database field and I know how to get data from database and save it as file. But the problem is that I need to read image data from the field and show that image in the picture box (WITHOUT saving it to temporary file).

aleksey_nycAuthor Commented:
There was a link in one of the posts on this site...

Unfortunately it is down now... but it had the closest solution i could find to what i was looking for. One thing that I didnt like is that it was using third-party library, which takes almost half a meg of space. I cant afford to load that library into the memory just for 3-4 functions that coded uses. :(

PS: no problem about the project :)
don worry,there a lot of experts here,they will help you :)
just wait 24 hours,i am sure you will received new comments :)
Try this,I get from PAQ Accept Answer:

Store the Image in the database as an ole object. myRs!FileHold

Store the file name as a text object in the database. myRs!FileName

Put an image box on the form.

On click of the button,

FileName = myRs!FileName
Open FileName For Binary Access Write As #1
lngTotalSize = myRs!FileHold.FieldSize
ReDim yBinaryData(lngTotalSize) As Byte
yBinaryData = myRs!JPEGFront.GetChunk(0, lngTotalSize)
Put #1, , yBinaryData
Close #1

Image1.Picture = LoadPicture(FileName)

You can put the data in by doing this backwards
As i see,most of them won't store image inside database,due to field type blod and binary
will eat your resource and can slow down your Computer.
They will create a file server to do this,unless other security issue.
ignore the comments i get from PAQ.thank
aleksey_nyc ,have you download ?
I modify the code and i can directly use image control to display Picture that store inside database.
without convert to temp file.
it is you want ?
if yes,i will post the code.
I try this just like you:
" I've tried the trick with DataSource and DataField properties of PictureBox. It was working but now it shows me the error saying Class Not registered or something..."
so,i think you have to post complete error msg,then we can find out what's going on...
aleksey_nycAuthor Commented:
I've posted error. Its my second post over here. Look right after second yours ( And I did download this code, but the one you gave me uses temporary file.

"Open "tmp.bmp" For Binary Access Write As #F" <- I dont want to do that

But if you said that you managed to do it without convert to temp file, then sure.. post it... hopefully it will give us some ideas.

May i know how do you distribute your program ? when you distribute your program
without using "Package and Deployment Wizard",You will missing a lot of supporting
file, like "MS Binding Collection object" (CLSID:{59245250-7A2F...)

-Pls try to install MDAC2.7 to recover or install missing file.
-also WSH6.0.

Pls try and post the result,thank's...

aleksey_nycAuthor Commented:
I am not yet distributing the application. That happens on my dev machine. Reinstalling MDAC2.7 didnt help and what is WSH6.0?
aleksey_nycAuthor Commented:
One more thing about that class... If I go to Project References i see Microsoft Data Binding Collection checked and doesnt have MISSING text like sometimes it shows.
Read for my BLOB handling method,

Then read the thread at where pushing to a picturebox without temporary files is discussed.
aleksey_nycAuthor Commented:
Hey Squeebee!

I've read your post about the same thing -

Thats very close to what I am looking for. But still, it requires me to use third-party library. But is there a way to perform BLOB -> StdPicture operation without third-party libraries?

No. But this is not much of a stretch, it's calls to two standard Windows APIs and a type library. It's not like you are depending on a vendor or worrying about licensing.

Oh, and it may be worth mention that you can do this directly in .NET
in my opinion,you should fix your dev machine problem,this is for future.
it was so easy to bind recordset to recordset for display picture,
and i think this is correct way to display your picture.You should make your
code simple and easy to manage,right.
wsh = windows scripting host
i have some idea to fix your problem,wait a minute...
Just find out that class and register you step by step,pls wait...
1.Close all your program. this class {59245250-7A2F-11D0-9482-00A0C91110ED} make you headache?

if not this one then pls make a search in regedit to get it component path.
else go step 3

2.1.when you see the Clsid,inside sub tree 'InprocServer32'-'data' will show
you the path.

2.2.Copy the value inside,this is component path.

3.Goto 'Start'-'Run' then type: Regsvr32 C:\WINNT\System32\MSBIND.DLL

4.Restart Computer

-if not work then Restart your Computer and try again from step 1
(Restart PC to release the class,maybe in use by windows or other program)

-Lastly,Please post the result.
aleksey_nycAuthor Commented:
I fixed the error message...

I installed SP5... but i am just wondering what made it stop working in the first place... :-/
aleksey_nycAuthor Commented:
I tried to search for that CLSID in the registry, but it wasnt there... but i havent tried to use RegSvr32... but its too late, its working now. Well, i guess i'll have to stick to DataSouce/DataField trick for now. :-/
OIC,becoz MSBIND.DLL have been repair and register again when you install SP5.
n.mind,all is same :)
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- PAQ'd and points refunded

Please leave any comments here within the next four days.


Cleanup Volunteer
PAQed, with points refunded (250)

Community Support Cleanup Moderator

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.