Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / Database Access / September 2008



Tip: Looking for answers? Try searching our database.

Save a picturebox Picture into a Long Binary (OLE Object) field in a mdb

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Paulo - 02 Sep 2008 13:12 GMT
Hi all,

I want to save the Picture object into a Long Binary (OLE Object) field in a
mdb database without using the data control. Could not find any direction
searching the web.

Anyone knows an example?

Thanks in advance.

Paulo
Ralph - 03 Sep 2008 04:04 GMT
> Hi all,
>
[quoted text clipped - 3 lines]
>
> Anyone knows an example?

Your post is a bit confusing since you use the expression "Long Binary (OLE
Object) field". Note these are actually two different things. While
internally the storage may be the same - Jet handles them as two distinct
datatypes. For example, Dates are nothing more than a double, but Jet knows
Doubles and Dates.

[Also I'm assuming your are using Classic VB (VB6 and lower) and not dotNet.
DotNet provides additional tools for binding images from storage with
controls. If using dotNet you need to post to a dotNet newsgroup and ask
about .DataBindings and .MemoryStream.]

Since you posted to a DAO newsgroup, I am assuming you are using DAO. AFAIK,
you cannot do this with DAO without going through the OLE Container control.
(Hopefully I'm wrong. I often am. But I have never seen any code to do it.
But again what in programming is impossible?)

You can do it without the OLE Container control with ADO using AppendChunk.
With yet one more fly in the ointment - you can load a 'file' or the binary
of the picture - but no practical way in VB to load the 'PictureBox' without
the OLE Container control.  That's why you use it - it wraps your image as
an OLE Object.

Last I have to add this piece of unsolicited advice. Adding pictures and
other binary objects to a MSAccess 'file-based' database seems like a good
idea. It sure looks neat in the demos and tutorials. But it scales very
poorly. It doesn't take many objects to throughly bloat an mdb file which
will effect performance and maintance. The problems will go up geometrically
if the database is shared.

A better strategy is store your 'pictures' as separate files and keep the
location and name in the database. You can wrap this location with code to
provide management.

-ralph
Paulo - 06 Sep 2008 15:45 GMT
Hi Ralph,

Thanks for replying. I am using classic vb (VB6) and DAO 3.51 Object
Library. At this moment I could already resolve my problem. I found a
corresponding example with ADO at VB Helper here:

http://www.vb-helper.com/howto_db_dib.html

Is this case I am maintaining an old application and adding a few new
capabilities, one of them is to store companies logos and other images. The
field is of type dbLongBinary (type 11). By using the AppendChunk and
GetChunk methods it is possible to save and load any DIB bits. The database
file (MDB) is shared in a machine of the costumer's network and at this
moment the application has been tested and accessed by more than 15 people
simultaneously. No problems found till now.

It would have been very hard to rewrite the entire application in .net, so
my chance is to maintain it as long as I can...

Thanks Ralph
Ralph - 09 Sep 2008 08:46 GMT
> Hi Ralph,
>
[quoted text clipped - 16 lines]
>
> Thanks Ralph

Thanks for the feedback.

ADO AppendChunk/GetChunk is usually the best solution. My warning was more
directed to 'quanity' and not to problems with the storage and retrieval
itself.

-ralph
Sizeof() - 08 Sep 2008 14:02 GMT
> Hi all,
>
[quoted text clipped - 7 lines]
>
> Paulo

Hello Paulo,

Excusez mon anglais, mais il me semble que c'est ce que vous cherchez
(VB5 sp2)

Salutations et bon code...
SO

' ##########

Option Explicit

Dim db As Database
Dim wrkDefault As Workspace
Dim rs As Recordset

Dim tableau() As Byte, ff

Private Sub Command1_Click()

ff = FreeFile

   Open "c:\windows\test.bmp" For Binary As #ff
       ReDim tableau(1 To LOF(ff))
       Get #ff, , tableau
   Close #ff

Set wrkDefault = DBEngine.Workspaces(0)

If Dir(App.Path & "\BD1.MDB") <> "" Then Kill App.Path & "\BD1.MDB"

Set db = wrkDefault.CreateDatabase(App.Path & "\BD1.MDB", dbLangGeneral)
db.Execute "CREATE TABLE table1 " & "(champ1 LONGBINARY);"
db.Close

Set db = OpenDatabase(App.Path & "\BD1.MDB")
Set rs = db.OpenRecordset("Table1", dbOpenDynaset)

rs.AddNew
rs!champ1 = tableau

   Open App.Path & "\resultat.bmp" For Output As #ff
       Print #ff, StrConv(rs.Fields(0), vbUnicode);
   Close #ff

rs.Update

db.Close

End Sub

' ##########
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.