473,387 Members | 1,502 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,387 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 12558
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.