-
Apr 20th, 2005, 07:29 PM
#1
Thread Starter
Fanatic Member
-
Apr 20th, 2005, 07:44 PM
#2
Re: Picture in ACCESS
Here is a sample procedure to store image:
VB Code:
Public Sub AddNewImage(rstTemp As ADODB.Recordset, _
sTitle As String, sFileName As String)
'=============================================================
Dim file_num As String
Dim file_length As Long
Dim bytes() As Byte
Dim num_blocks As Long
Dim left_over As Long
Dim block_num As Long
On Error GoTo ErrHandler
rstTemp.Find "Title='" & sTitle & "'"
file_num = FreeFile
Open sFileName For Binary Access Read As #file_num
file_length = LOF(file_num)
If file_length > 0 Then
num_blocks = file_length / BLOCK_SIZE
left_over = file_length Mod BLOCK_SIZE
rstTemp("fImageSize") = file_length
ReDim bytes(BLOCK_SIZE)
For block_num = 1 To num_blocks
Get #file_num, , bytes()
rstTemp("fImage").AppendChunk bytes()
Next block_num
If left_over > 0 Then
ReDim bytes(left_over)
Get #file_num, , bytes()
rstTemp("fImage").AppendChunk bytes()
End If
Close #file_num
End If
rstTemp.Update
Exit Sub
ErrHandler:
Debug.Print Err.Description
Err.Clear
'Resume Next
Exit Sub
End Sub
But KIM that storing PATH is a better approach, though.
-
Apr 20th, 2005, 07:47 PM
#3
-
Apr 20th, 2005, 07:49 PM
#4
Thread Starter
Fanatic Member
Re: Picture in ACCESS
thx RhinO.
from your code snippet i realise that .. with your same code any file can be stored in database like .exe,.jpg,.swf,.doc
because you are first gaining binary access then appending this chunk into database ...
M i right ..?
-
Apr 20th, 2005, 07:54 PM
#5
Re: Picture in ACCESS
Absolutely yes!
The only problem is that MS Access is limited to 2GB ... but realistically after databse file reaches 1GB you will notice performance issues so frequently compacting mdb is highly preferable.
-
Apr 20th, 2005, 08:01 PM
#6
Thread Starter
Fanatic Member
Re: Picture in ACCESS
 Originally Posted by RhinoBull
Absolutely yes!
The only problem is that MS Access is limited to 2GB ... but realistically after databse file reaches 1GB you will notice performance issues so frequently compacting mdb is highly preferable.
thx deU & RhinO
it means RhinO if we are using Oracle,mySQL then no Problem ..
-
Apr 20th, 2005, 08:14 PM
#7
Re: Picture in ACCESS
I haven't used it with MySql but Oracle, SQL Server, Sybase are fine.
-
Apr 20th, 2005, 08:52 PM
#8
Thread Starter
Fanatic Member
Re: Picture in ACCESS
thx RhinO
but unfortunately i cannot rate your post
it says
Spread your post any other place ( some thing like that )
-
Apr 20th, 2005, 09:04 PM
#9
Re: [Resolved] Picture in ACCESS
As you may already know I have no problem with that what so ever.
Cheers.
-
Apr 20th, 2005, 09:05 PM
#10
Re: [Resolved] Picture in ACCESS
Hey RB, what is BLOCK_SIZE defined as? Nice code btw
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 20th, 2005, 10:10 PM
#11
Re: [Resolved] Picture in ACCESS
Thanks Rob ... it's near 10K in my app but you may redefine it:
Public Const BLOCK_SIZE = 10000
-
Apr 20th, 2005, 10:11 PM
#12
Re: [Resolved] Picture in ACCESS
Oh, its a user defined const. Thanks.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 20th, 2005, 10:12 PM
#13
Re: [Resolved] Picture in ACCESS
-
Apr 21st, 2005, 07:13 PM
#14
Re: [Resolved] Picture in ACCESS
This might have some importance with you....
thx RhinO
but unfortunately i cannot rate your post
it says
Spread your post any other place ( some thing like that )
Why dont give me that rate instead?
-
Apr 11th, 2006, 07:48 PM
#15
Hyperactive Member
Re: [Resolved] Picture in ACCESS
RhinoBull, since you seem to be a guru in that field, my question is primarily aimed at you .......
I have a PictureBox filled with random colored pixels.
SavePicture pic1.Image, "c:\test\test.bmp" worked great. So I can now save test.bmp into a database. But what if I wanted to skip that step, and save the PictureBox *DIRECTLY* into my database... Can that be done?
I would appreciate to avoid saving the picture to disk first.
Thanks
-
Apr 11th, 2006, 08:47 PM
#16
Re: [Resolved] Picture in ACCESS
 Originally Posted by Krass
...I would appreciate to avoid saving the picture to disk first...
Why? What's the problem with that? You save it to disk, then to your database and then delete the file if you wish not to keep it...
-
May 20th, 2006, 02:25 AM
#17
Hyperactive Member
Re: [Resolved] Picture in ACCESS
Oh.. yes. This actually works great. Thanks.
I just usually try to avoid unnecessary steps. Even tho I still believe there *should* be a way, I wouldn't even bother to change my code, at that point.
Thank you
-
Jan 26th, 2007, 07:50 PM
#18
New Member
Re: [Resolved] Picture in ACCESS
RB! do you have any codes that can make commandbutton into xp style without using a user control/class module. API? thanks!
-
Jan 26th, 2007, 09:02 PM
#19
Re: [Resolved] Picture in ACCESS
Welcome to Forums, tgcngb!
But how's your question relevant to this thread?
-
Jan 27th, 2007, 05:58 PM
#20
New Member
Re: [Resolved] Picture in ACCESS
sorry. i forgot to think of the topic. but, if you still have something, hope you can share it. thanks!
-
Jan 27th, 2007, 06:24 PM
#21
Re: [Resolved] Picture in ACCESS
Try to use the search - it's very handy. Searching this forum for something like "XP styles" will most definitely return you bunch of pages with samples.
-
Jan 29th, 2007, 03:14 AM
#22
New Member
Re: [Resolved] Picture in ACCESS
-
May 14th, 2007, 04:53 AM
#23
New Member
Re: [Resolved] Picture in ACCESS
Hi guys,
do you know how can i use this code with vb2005?
= RhinoBull's posted - The insertion pictor to database =
-
May 14th, 2007, 07:35 AM
#24
Re: [Resolved] Picture in ACCESS
It's not designed for VB.Net.
-
May 15th, 2007, 02:54 AM
#25
New Member
Re: [Resolved] Picture in ACCESS
Thanks Rhino. But expected similar result, for vb.net, how i write the code?
-
Sep 20th, 2007, 05:17 AM
#26
Hyperactive Member
Re: [Resolved] Picture in ACCESS
If I want to save the file or image to database
What type of Data Type i should use ?
Thanks for advice
Where there is no hope, there can be no endeavor.
There are two ways of rising in the world, either by your own industry or by the folly of others.
-
Sep 20th, 2007, 07:18 AM
#27
Hyperactive Member
Re: [Resolved] Picture in ACCESS
hey nUflAvOrS..
I use the "OLE Object" data type in my databases to store pictures......
-
Sep 20th, 2007, 07:32 AM
#28
Re: [Resolved] Picture in ACCESS
That would be any type that is compatible with BLOB - different db engines have different naming conventions but some of them identical so you really need to experiment.
-
Oct 1st, 2007, 08:50 PM
#29
Hyperactive Member
Re: [Resolved] Picture in ACCESS
Thanks Krass and RhinoBull, I will try your method.
If got any problem i will ask the question here again.
Thanks !
Where there is no hope, there can be no endeavor.
There are two ways of rising in the world, either by your own industry or by the folly of others.
-
Sep 9th, 2010, 12:57 AM
#30
Hyperactive Member
Re: Picture in ACCESS
It isn't run, I sent to attachments file: http://www.mediafire.com/?j0kq1ityoch7r9i , can you help me ?
 Originally Posted by RhinoBull
Here is a sample procedure to store image:
VB Code:
Public Sub AddNewImage(rstTemp As ADODB.Recordset, _
sTitle As String, sFileName As String)
'=============================================================
Dim file_num As String
Dim file_length As Long
Dim bytes() As Byte
Dim num_blocks As Long
Dim left_over As Long
Dim block_num As Long
On Error GoTo ErrHandler
rstTemp.Find "Title='" & sTitle & "'"
file_num = FreeFile
Open sFileName For Binary Access Read As #file_num
file_length = LOF(file_num)
If file_length > 0 Then
num_blocks = file_length / BLOCK_SIZE
left_over = file_length Mod BLOCK_SIZE
rstTemp("fImageSize") = file_length
ReDim bytes(BLOCK_SIZE)
For block_num = 1 To num_blocks
Get #file_num, , bytes()
rstTemp("fImage").AppendChunk bytes()
Next block_num
If left_over > 0 Then
ReDim bytes(left_over)
Get #file_num, , bytes()
rstTemp("fImage").AppendChunk bytes()
End If
Close #file_num
End If
rstTemp.Update
Exit Sub
ErrHandler:
Debug.Print Err.Description
Err.Clear
'Resume Next
Exit Sub
End Sub
But KIM that storing PATH is a better approach, though. 
-
Sep 9th, 2010, 06:37 AM
#31
Re: [Resolved] Picture in ACCESS
Why don't you open a new thread (with meaningful title) and explain in details what you do, how you do it and what isn't working?
Thanks.
-
Sep 16th, 2010, 03:43 AM
#32
Hyperactive Member
Re: [Resolved] Picture in ACCESS
The compress this file, this is example for yourself, the subject pictures insert into database and picture load from database up PictureBox or Image are very rare. I was copy your source code in VB6.0 and try run but it is not, so ask you. I want to know directions for use and declare. If i know, i never ask you.
-
Jul 21st, 2011, 03:11 AM
#33
Addicted Member
Re: [Resolved] Picture in ACCESS
If you need to store a picture into your database and want to read it directly into a picturebox (or any Picture(IPictureDisp) property) without first having to write the image to the tempfolder(or any folder) and use loadimage, you can use the propertybag... I found this method somewhere and I found it ingenius use of VB specific methods:
Field ImageData is of varbinary type.
Code:
Private Const csPropertyBagNameImageData As String = "ImageData"
Private property_picPicture As IPictureDisp
Private Sub ReadRecord(ByVal rs As RecordSet)
Dim abBuffer() As Byte
Dim PB As PropertyBag
If IsNull(rs.Fields!ImageData) Then
Set property_picPicture = Nothing
Else
abBuffer() = rs.Fields!ImageData
Set PB = New PropertyBag
PB.Contents = abBuffer()
Set property_picPicture = PB.ReadProperty(csPropertyBagNameImageData)
Set PB = Nothing
End If
End Sub
Private Sub pWriteRecord(ByVal rs As RecordSet)
Dim PB As PropertyBag
If property_picPicture Is Nothing Then
rs.Fields!ImageData = Null
Else
Set PB = New PropertyBag
Call PB.WriteProperty(csPropertyBagNameImageData, property_picPicture)
rs.Fields!ImageData = PB.Contents
Set PB = Nothing
End If
Call rs.Update
End Sub
The above code only has problems with image of ICON type, which will not have it's transparency anymore and the palet is fubar, but I never bothered YET to find a solution for that..
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|