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

This is a discussion on Save a picturebox Picture into a Long Binary (OLE Object) field in a mdb within the ADO DAO RDO RDS forums in Framework and Interface Programming category; 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...

Go Back   Application Development Forum > Framework and Interface Programming > ADO DAO RDO RDS

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 09-02-2008, 08:12 AM
Paulo
Guest
 
Default Save a picturebox Picture into a Long Binary (OLE Object) field in a mdb

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


Reply With Quote
  #2  
Old 09-02-2008, 11:04 PM
Ralph
Guest
 
Default Re: Save a picturebox Picture into a Long Binary (OLE Object) field in a mdb


"Paulo" <nospam.pmp_costa@netcabo.pt> wrote in message
news:uJKOoSPDJHA.5196@TK2MSFTNGP04.phx.gbl...
> 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?
>


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




Reply With Quote
  #3  
Old 09-06-2008, 10:45 AM
Paulo
Guest
 
Default Re: Save a picturebox Picture into a Long Binary (OLE Object) field in a mdb

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


Reply With Quote
  #4  
Old 09-08-2008, 09:03 AM
Sizeof\(\)
Guest
 
Default Re: Save a picturebox Picture into a Long Binary (OLE Object) field in a mdb


"Paulo" <nospam.pmp_costa@netcabo.pt> a écrit dans le message de news:
uJKOoSPDJHA.5196@TK2MSFTNGP04.phx.gbl...
> 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
>
>




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

' ##########



Reply With Quote
  #5  
Old 09-09-2008, 03:46 AM
Ralph
Guest
 
Default Re: Save a picturebox Picture into a Long Binary (OLE Object) field in a mdb


"Paulo" <nospam.pmp_costa@netcabo.pt> wrote in message
news:%23Z$5A7CEJHA.1280@TK2MSFTNGP02.phx.gbl...
> 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
>


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


Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 10:31 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.