Solved

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

Posted on 2003-10-27
31
590 Views
Last Modified: 2013-12-25
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
Comment
Question by:aleksey_nyc
  • 17
  • 10
  • 2
  • +2
31 Comments
 
LVL 8

Expert Comment

by:MYLim
ID: 9631090
Please post your code and error.
0
 
LVL 8

Expert Comment

by:MYLim
ID: 9631101
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
 
LVL 8

Expert Comment

by:MYLim
ID: 9631143
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
 

Author Comment

by:aleksey_nyc
ID: 9631150

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
 

Author Comment

by:aleksey_nyc
ID: 9631173
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
 
LVL 8

Expert Comment

by:MYLim
ID: 9631186
0
 
LVL 8

Expert Comment

by:MYLim
ID: 9631275
ya,i know that after i chk that project,sorry.
0
 

Author Comment

by:aleksey_nyc
ID: 9631283
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
 

Author Comment

by:aleksey_nyc
ID: 9631323
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
 
LVL 8

Expert Comment

by:MYLim
ID: 9631584
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
 
LVL 8

Expert Comment

by:MYLim
ID: 9631598
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
 
LVL 8

Expert Comment

by:MYLim
ID: 9631618
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
 
LVL 8

Expert Comment

by:MYLim
ID: 9631654
ignore the comments i get from PAQ.thank
0
 
LVL 8

Expert Comment

by:MYLim
ID: 9631771
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
 
LVL 8

Expert Comment

by:MYLim
ID: 9631798
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:aleksey_nyc
ID: 9631823
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
 
LVL 8

Expert Comment

by:MYLim
ID: 9631884
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
 

Author Comment

by:aleksey_nyc
ID: 9634888
I am not yet distributing the application. That happens on my dev machine. Reinstalling MDAC2.7 didnt help and what is WSH6.0?
0
 

Author Comment

by:aleksey_nyc
ID: 9634920
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
 
LVL 17

Expert Comment

by:Squeebee
ID: 9637627
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
 

Author Comment

by:aleksey_nyc
ID: 9637773
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
 
LVL 17

Expert Comment

by:Squeebee
ID: 9637868
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
 
LVL 8

Expert Comment

by:MYLim
ID: 9638279
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
 
LVL 8

Expert Comment

by:MYLim
ID: 9638396
i have some idea to fix your problem,wait a minute...
0
 
LVL 8

Expert Comment

by:MYLim
ID: 9638426
Just find out that class and register again.show you step by step,pls wait...
0
 
LVL 8

Expert Comment

by:MYLim
ID: 9638527
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
 

Author Comment

by:aleksey_nyc
ID: 9638529
I fixed the error message...

I installed SP5... but i am just wondering what made it stop working in the first place... :-/
0
 

Author Comment

by:aleksey_nyc
ID: 9638540
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
 
LVL 8

Expert Comment

by:MYLim
ID: 9638542
OIC,becoz MSBIND.DLL have been repair and register again when you install SP5.
n.mind,all is same :)
0
 
LVL 1

Expert Comment

by:ayufans
ID: 10390711
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
 

Accepted Solution

by:
amp072397 earned 0 total points
ID: 10426969
PAQed, with points refunded (250)

amp
Community Support Cleanup Moderator
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

708 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

13 Experts available now in Live!

Get 1:1 Help Now