Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 613
  • Last Modified:

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!!
0
aleksey_nyc
Asked:
aleksey_nyc
  • 17
  • 10
  • 2
  • +2
1 Solution
 
MYLimCommented:
Please post your code and error.
0
 
MYLimCommented:
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
0
 
MYLimCommented:
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
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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
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.
0
 
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).

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

Thanks
0
 
aleksey_nycAuthor Commented:
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 :)
0
 
MYLimCommented:
don worry,there a lot of experts here,they will help you :)
just wait 24 hours,i am sure you will received new comments :)
0
 
MYLimCommented:
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
0
 
MYLimCommented:
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.
0
 
MYLimCommented:
ignore the comments i get from PAQ.thank
0
 
MYLimCommented:
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.
0
 
MYLimCommented:
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...
0
 
aleksey_nycAuthor Commented:
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..
0
 
MYLimCommented:
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...

0
 
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?
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.
0
 
SqueebeeCommented:
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.
0
 
aleksey_nycAuthor Commented:
Hey Squeebee!

I've read your post about the same thing - http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/VB_Databases/Q_20570874.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
0
 
SqueebeeCommented:
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
0
 
MYLimCommented:
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
0
 
MYLimCommented:
i have some idea to fix your problem,wait a minute...
0
 
MYLimCommented:
Just find out that class and register again.show you step by step,pls wait...
0
 
MYLimCommented:
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.
0
 
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... :-/
0
 
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. :-/
0
 
MYLimCommented:
OIC,becoz MSBIND.DLL have been repair and register again when you install SP5.
n.mind,all is same :)
0
 
ayufansCommented:
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
0
 
amp072397Commented:
PAQed, with points refunded (250)

amp
Community Support Cleanup Moderator
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 17
  • 10
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now