473,320 Members | 1,910 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How do i store OLE Object (JPG) file to database

Dear sir

I m Software Engineer in Software co.


My question is how do i Store OLE Object (JPG) file to database
AppendChunk

plz Help me
Jul 5 '06 #1
7 12549
neonk
4
Pass the OLE Picture Object and the ADO Database field to the following code. It's not pretty since it uses an intermediate Windows File, but it is the shortest piece of code I know. There are other methods using In Memory files, etc.

To be honest I use the LEAD Tools Image Object that has a SAVE command.

Neon K.


Expand|Select|Wrap|Line Numbers
  1.  
  2. Public Sub WriteImage(ByRef pPict As StdPicture, ByRef pField As ADODB.Field)
  3.  
  4. On Error Resume Next
  5.  
  6. Dim strStream As New ADODB.Stream
  7.  
  8. strStream.Type = adTypeBinary
  9. strStream.Open
  10. Call SavePicture(pPict, "TempTemp.bmp")
  11. strStream.LoadFromFile ("TempTemp.bmp")
  12. pField.Value = strStream.Read
  13. Kill "TempTemp.bmp"
  14. strStream.Close
  15.  
  16. End Sub
  17.  
Jul 5 '06 #2
sashi
1,754 Expert 1GB
Hi there,

below are some sample to store and to retrieve images from and to BLOB field.. give it a try..

retrieve from BLOB field
Expand|Select|Wrap|Line Numbers
  1. Public Sub getBLOB(RS As ADODB.Recordset, Field As String, Des As String)
  2.     Dim lngFieldSize As Long
  3.     Dim fileBytes() As Byte
  4.     Dim intFileHandle As Integer
  5.  
  6.     intFileHandle = FreeFile
  7.  
  8.     lngFieldSize = RS(Field).ActualSize
  9.     If lngFieldSize > 0 Then
  10.         fileBytes = RS(Field).GetChunk(lngFieldSize)
  11.         Open Des For Binary As intFileHandle
  12.             Put intFileHandle, , fileBytes
  13.         Close intFileHandle
  14.     End If
  15. End Sub
  16.  
store to BLOB field
Expand|Select|Wrap|Line Numbers
  1. Public Sub setBLOB(RS As ADODB.Recordset, Field As String, Source As String)
  2.     Dim fileBytes() As Byte
  3.     Dim intFileHandle As Integer
  4.  
  5.     intFileHandle = FreeFile
  6.  
  7.     Open Source For Binary As intFileHandle
  8.         fileBytes = InputB(LOF(intFileHandle) - 1, intFileHandle)
  9.         RS(Field).AppendChunk fileBytes
  10.     Close intFileHandle
  11. End Sub
  12.  
sample usage
Expand|Select|Wrap|Line Numbers
  1. setBLOB myRecordSet, "FileField", "c:\myfile.gif" ' Places file into database
  2.  
  3. getBLOB myRecordSet, "FileField", "c:\myfile_extracted_from_database.gif"
  4.  
good luck my fren.. :)
Jul 6 '06 #3
Skiran
5
Hi there,

below are some sample to store and to retrieve images from and to BLOB field.. give it a try..

retrieve from BLOB field
Expand|Select|Wrap|Line Numbers
  1. Public Sub getBLOB(RS As ADODB.Recordset, Field As String, Des As String)
  2.     Dim lngFieldSize As Long
  3.     Dim fileBytes() As Byte
  4.     Dim intFileHandle As Integer
  5.  
  6.     intFileHandle = FreeFile
  7.  
  8.     lngFieldSize = RS(Field).ActualSize
  9.     If lngFieldSize > 0 Then
  10.         fileBytes = RS(Field).GetChunk(lngFieldSize)
  11.         Open Des For Binary As intFileHandle
  12.             Put intFileHandle, , fileBytes
  13.         Close intFileHandle
  14.     End If
  15. End Sub
  16.  
store to BLOB field
Expand|Select|Wrap|Line Numbers
  1. Public Sub setBLOB(RS As ADODB.Recordset, Field As String, Source As String)
  2.     Dim fileBytes() As Byte
  3.     Dim intFileHandle As Integer
  4.  
  5.     intFileHandle = FreeFile
  6.  
  7.     Open Source For Binary As intFileHandle
  8.         fileBytes = InputB(LOF(intFileHandle) - 1, intFileHandle)
  9.         RS(Field).AppendChunk fileBytes
  10.     Close intFileHandle
  11. End Sub
  12.  
sample usage
Expand|Select|Wrap|Line Numbers
  1. setBLOB myRecordSet, "FileField", "c:\myfile.gif" ' Places file into database
  2.  
  3. getBLOB myRecordSet, "FileField", "c:\myfile_extracted_from_database.gif"
  4.  
good luck my fren.. :)
Is there any other method to do this?
because after using this code it stores image as Long binary data. If you do the same With using MsAccess's form, it stores as Bitmap file. If we are handling Big database, then above example will make any differance to speed of accessing database?
Plz reply waiting
Nov 2 '06 #4
sashi
1,754 Expert 1GB
Hi there,

Another option will be converting BMP to JPG format respectively, take a look at below attached link, hope it helps. Good luck & take care.

http://www.vbaccelerator.com/home/VB...ry/article.asp

Is there any other method to do this?
because after using this code it stores image as Long binary data. If you do the same With using MsAccess's form, it stores as Bitmap file. If we are handling Big database, then above example will make any differance to speed of accessing database?
Plz reply waiting
Nov 2 '06 #5
im also looking and still in progress of implementation "How do i store OLE Object (JPG) file to database( MS-ACCESS and SQL SERVEr2000) for my recent project..as soon as i will provide whole source code.in .ZIP format

take care
from geoamins.uni.cc
Jan 6 '07 #6
ikebiz
1
hi co-scrpiters

would you send me a running visual basic code for uploading and retrieving images from mysql database?

here is my email address mil id removed
please....

because i tried so many codes that i have seen over the net but none of them will run... i think there something maybe on my code that i have to refresh..
please send it to me... it will be very much appreciated...
thnx all and god bless us all scripters...

ikebiz...
Jan 30 '08 #7
debasisdas
8,127 Expert 4TB
Please find related discussions here and here .
Jan 30 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Lars Behrens | last post by:
Hi there! For a web project I need a little expert help. I don't have written much code yet, just been fiddling around a bit, testing and planning. The web site will have a submission page for...
3
by: David Stockwell | last post by:
Hi, I'd like to read the contents of a file into memory. The problem is that this file is binary. I then want to store the whole thing in memory to a database as a blob. I have no problem...
3
by: Karen Grube | last post by:
Hi! Each week, we receive a two-page PDF file from UPS along with a separate flat file (a CSV) The PDF file contains the overview of our weekly invoice and the CSV contains the details of each...
3
by: DL | last post by:
Hi, Many questions have already been asked and answered about images in Access... But despite having searched, I have not found an answer to the following question... In my DB, several forms...
3
by: nigel.thomson | last post by:
Hello All Is there an easy way to do this? I have a database that contains records witha image as one of the fields, what I want to do is export the images to a seperate folder, in whatever...
10
by: Paul Cheetham | last post by:
Hi, I am developing an application that needs to store some machine-specific settings. The application is going to be published on the network in order to keep the clients on the latest version....
3
by: JM | last post by:
Before storing information from a form in database I perform follwing operations on it : $path = mysql_real_escape_string(strip_tags(trim(urldecode($_POST)))); $summary =...
0
by: harshad | last post by:
Dear All,Here I am facing problem to store image.I am trying to store byte array(image) in to session variable so at time of update I will got that byte array and I do my update. here i am given...
2
by: gm000 | last post by:
hi i m using radiobuttonlist with images like this <asp:RadioButtonList ID="rbtnthumb1" runat="server"> <asp:ListItem Value ="News_icon.jpg"> <img...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.