Home > Archive > Visual Basic Syntax > February 2006 > Insert bitmap into access database field
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Insert bitmap into access database field
|
|
|
| Hello,
I need to Add and/or Insert a bitmap (C:\Test.bmp) into a new or existing
access database record (Employee.dig_signature) and have it saved as a
bitmap image.
I am currently using this statement in a click event.
rs.AddNew
rs.Fields("employee_signature").Value = pByteA
rs.Update
but it is saved as long binary data. How can I save this the way I need it?
Thanks
Rick
| |
| Larry Rebich 2006-02-17, 7:01 pm |
| Rick:
Some years ago I wrote a tip of the month that I call 'Store then Retrieve a
File from a Jet Database Field'. Link to http://www.buygold.net/tips then
look for the October 2000 tip of the month. A sample program is provided.
From the tip's intro:
"I recently had a requirement to store a picture in a Jet [Access] database.
I had never done this before so I posted a question in a couple of the news
groups. I got suggestions on how to store the picture but I didn't get any
real code - so I wrote some VB code to test the suggestions. I generalized
the code, encapsulated it in a DLL, and decided to make it the October
tip-of-the-month."
Cheers,
Larry Rebich
More tips link to:
http://www.buygold.net/tips
Please:
No personal e-mail questions :-)
"BOB" <NO@SPAM.NET> wrote in message
news:exBkB38MGHA.3856@TK2MSFTNGP12.phx.gbl...
> Hello,
>
> I need to Add and/or Insert a bitmap (C:\Test.bmp) into a new or existing
> access database record (Employee.dig_signature) and have it saved as a
> bitmap image.
> I am currently using this statement in a click event.
>
> rs.AddNew
> rs.Fields("employee_signature").Value = pByteA
> rs.Update
>
> but it is saved as long binary data. How can I save this the way I need
> it?
>
> Thanks
>
> Rick
>
>
| |
| Paul Clement 2006-02-17, 7:01 pm |
| On Fri, 17 Feb 2006 09:24:14 -0500, "BOB" <NO@SPAM.NET> wrote:
¤ Hello,
¤
¤ I need to Add and/or Insert a bitmap (C:\Test.bmp) into a new or existing
¤ access database record (Employee.dig_signature) and have it saved as a
¤ bitmap image.
¤ I am currently using this statement in a click event.
¤
¤ rs.AddNew
¤ rs.Fields("employee_signature").Value = pByteA
¤ rs.Update
¤
¤ but it is saved as long binary data. How can I save this the way I need it?
See if the following helps:
How To Read and Write BLOBs Using GetChunk and AppendChunk
http://support.microsoft.com/default.aspx/kb/194975
Paul
~~~~
Microsoft MVP (Visual Basic)
| |
|
| When I needed to do this myself I found a few examples on ms.com and
elsewhere but none of them seemed to work that well. I rewrote the below
function and it seems to work ok.
This function updates the first row in a recordset with the passed file.
The recordset should contain the primary key of the record as well as
the BLOB field otherwise you get a "missing key" error.
Private Const BlockSize = 32000
Function fcnLoadBlobIntoDatabase(SourceFile As String, _
r As Recordset, sField As String) As Boolean
Dim NumBlocks As Integer, F As Integer, i As Integer
Dim FileLength As Long, LeftOver As Long
Dim FileData() As Byte
On Error GoTo Err_ReadBLOB
'open the source file for access
F = FreeFile
Open SourceFile For Binary Access Read As F
' Get the length of the file.
FileLength = LOF(F)
If FileLength = 0 Then Exit Function
' Calculate the number of blocks to read and leftover bytes.
LeftOver = FileLength Mod BlockSize
NumBlocks = (FileLength - LeftOver) \ BlockSize
'Now load read the file in blocks and load into FileData
Do While i <= NumBlocks
'size FileData as per blocksize of the same size
'as the remaining data
If i < NumBlocks Then
ReDim FileData(BlockSize - 1)
Else
ReDim FileData(LeftOver - 1)
End If
'Read the data from the file into FileData
Get F, , FileData
'append to our BLOB field
r(sField).AppendChunk (FileData)
'increment our block counter
i = i + 1
Loop
' Update the record - we're done
r.Update
fcnLoadBlobIntoDatabase = True
Err_ReadBLOB:
r.close
On Error Resume Next
Close F
End Function
BOB wrote:
> Hello,
>
> I need to Add and/or Insert a bitmap (C:\Test.bmp) into a new or existing
> access database record (Employee.dig_signature) and have it saved as a
> bitmap image.
> I am currently using this statement in a click event.
>
> rs.AddNew
> rs.Fields("employee_signature").Value = pByteA
> rs.Update
>
> but it is saved as long binary data. How can I save this the way I need it?
>
> Thanks
>
> Rick
>
>
| |
|
| Thanks everyone for responding.
I still am having an issue with the way the data is being saved in the
database. Maybe I'm not holding my tongue right.
Every thing seems to be saving the bitmap as a Long binary data type instead
of a Binary Image. What I am trying to accomplish is this. I need to display
this field in a Crystal Report but Crystal will only display it if it is a
Binary Image.
So looking at the whole picture, what is my best solution?
Rick
"Gman" <nah> wrote in message news:eBiqbR9MGHA.524@TK2MSFTNGP09.phx.gbl...[color=darkred]
> When I needed to do this myself I found a few examples on ms.com and
> elsewhere but none of them seemed to work that well. I rewrote the below
> function and it seems to work ok.
>
> This function updates the first row in a recordset with the passed file.
> The recordset should contain the primary key of the record as well as
> the BLOB field otherwise you get a "missing key" error.
>
> Private Const BlockSize = 32000
>
> Function fcnLoadBlobIntoDatabase(SourceFile As String, _
> r As Recordset, sField As String) As Boolean
>
> Dim NumBlocks As Integer, F As Integer, i As Integer
> Dim FileLength As Long, LeftOver As Long
> Dim FileData() As Byte
>
> On Error GoTo Err_ReadBLOB
>
> 'open the source file for access
> F = FreeFile
> Open SourceFile For Binary Access Read As F
>
> ' Get the length of the file.
> FileLength = LOF(F)
> If FileLength = 0 Then Exit Function
>
> ' Calculate the number of blocks to read and leftover bytes.
> LeftOver = FileLength Mod BlockSize
> NumBlocks = (FileLength - LeftOver) \ BlockSize
>
> 'Now load read the file in blocks and load into FileData
> Do While i <= NumBlocks
> 'size FileData as per blocksize of the same size
> 'as the remaining data
> If i < NumBlocks Then
> ReDim FileData(BlockSize - 1)
> Else
> ReDim FileData(LeftOver - 1)
> End If
>
> 'Read the data from the file into FileData
> Get F, , FileData
>
> 'append to our BLOB field
> r(sField).AppendChunk (FileData)
> 'increment our block counter
> i = i + 1
> Loop
>
> ' Update the record - we're done
> r.Update
>
> fcnLoadBlobIntoDatabase = True
>
> Err_ReadBLOB:
> r.close
> On Error Resume Next
> Close F
> End Function
>
>
> BOB wrote:
| |
| Paul Clement 2006-02-21, 7:04 pm |
| On Fri, 17 Feb 2006 16:04:55 -0500, "BOB" <NO@SPAM.NET> wrote:
¤ Thanks everyone for responding.
¤
¤ I still am having an issue with the way the data is being saved in the
¤ database. Maybe I'm not holding my tongue right.
¤ Every thing seems to be saving the bitmap as a Long binary data type instead
¤ of a Binary Image. What I am trying to accomplish is this. I need to display
¤ this field in a Crystal Report but Crystal will only display it if it is a
¤ Binary Image.
¤ So looking at the whole picture, what is my best solution?
The solution doesn't really change if Crystal Reports uses a file as its source. You still need to
save the binary from a database to a file first. I don't think it matter which data type you use to
store it as long as it supports a binary stream.
Paul
~~~~
Microsoft MVP (Visual Basic)
| |
| bob bonehead 2006-02-24, 7:02 pm |
| Thanks Paul,
I think I may be getting somewhere with this issue.
Thanks everyone
Rick
"Paul Clement" <UseAdddressAtEndofMessage@swspectrum.com> wrote in message
news:r5emv1hq9kgv7ctmn0ojb3hkaf6q4lohku@
4ax.com...
> On Fri, 17 Feb 2006 16:04:55 -0500, "BOB" <NO@SPAM.NET> wrote:
>
> ¤ Thanks everyone for responding.
> ¤
> ¤ I still am having an issue with the way the data is being saved in the
> ¤ database. Maybe I'm not holding my tongue right.
> ¤ Every thing seems to be saving the bitmap as a Long binary data type
> instead
> ¤ of a Binary Image. What I am trying to accomplish is this. I need to
> display
> ¤ this field in a Crystal Report but Crystal will only display it if it is
> a
> ¤ Binary Image.
> ¤ So looking at the whole picture, what is my best solution?
>
> The solution doesn't really change if Crystal Reports uses a file as its
> source. You still need to
> save the binary from a database to a file first. I don't think it matter
> which data type you use to
> store it as long as it supports a binary stream.
>
>
> Paul
> ~~~~
> Microsoft MVP (Visual Basic)
|
|
|
|
|