Link to home
Start Free TrialLog in
Avatar of aleksey_nyc
aleksey_nyc

asked on

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!!
Avatar of MYLim
MYLim

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

http://www.freevbcode.com/ShowCode.Asp?ID=1802
You can download a sample of this at :

http://www.marques.co.za/stefan/accessimage.zip

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
Avatar of aleksey_nyc

ASKER


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
objRS.Close
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.
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).

Thanks
ya,i know that after i chk that project,sorry.
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).

Thanks
There was a link in one of the posts on this site...
http://www.domaindlx.com/e_morcillo/scripts/cod/tips/pcarr.asp

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 accessimage.zip ?
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...
I've posted error. Its my second post over here. Look right after second yours (accessimage.zip). 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.

Thanks..
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...

I am not yet distributing the application. That happens on my dev machine. Reinstalling MDAC2.7 didnt help and what is WSH6.0?
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 http://www.vbmysql.com/articles/blobaccessvb.html for my BLOB handling method,

Then read the thread at http://www.vbmysql.com/forums/viewtopic.php?t=10 where pushing to a picturebox without temporary files is discussed.
Hey Squeebee!

I've read your post about the same thing - https://www.experts-exchange.com/questions/20570874/URGENT-BLOB-from-ADO-Stream-to-picturebox-WITHOUT-temp-files.html

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?

Thanks
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
aleksey_nyc:
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 again.show you step by step,pls wait...
1.Close all your program.

2.is 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.
I fixed the error message...

I installed SP5... but i am just wondering what made it stop working in the first place... :-/
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.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

ayufans
Cleanup Volunteer
ASKER CERTIFIED SOLUTION
Avatar of amp072397
amp072397

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial