473,385 Members | 1,402 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,385 developers and data experts.

BLOB - Save image to database

sashi
1,754 Expert 1GB
BLOB - Save image to database

BLOB's are a way of storing images in a database. The following procedure will show you how to create a connection to your database and how to store an image using BLOB.

Expand|Select|Wrap|Line Numbers
  1. Dim CN As New ADODB.Connection
  2. Dim RS As ADODB.Recordset
  3. Dim DataFile As Integer, Fl As Long, Chunks As Integer
  4. Dim Fragment As Integer, Chunk() As Byte, i As Integer, FileName As String
  5.  
  6. Private Const ChunkSize As Integer = 16384
  7. Private Const conChunkSize = 100
  8.  
  9. Private Sub cmdSave_Click()
  10.     CN.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=Pubs;Data Source=Test"
  11.     Dim strSQL As String
  12.  
  13.     strSQL = "SELECT * FROM pub_info where pub_id = '9999'"
  14.     RS.Open strSQL, CN, adOpenForwardOnly, adLockOptimistic
  15.  
  16.     RS.AddNew
  17.       SavePicture
  18.     RS.Update
  19.  
  20.     Set RS = Nothing
  21.     Set RS = New Recordset
  22. End Sub
  23.  
  24. Private Sub SavePicture()
  25.     Dim strFileNm As String
  26.     DataFile = 1
  27.     Open strFileNm For Binary Access Read As DataFile
  28.         Fl = LOF(DataFile)   ' Length of data in file
  29.         If Fl = 0 Then Close DataFile: Exit Sub
  30.         Chunks = Fl \ ChunkSize
  31.         Fragment = Fl Mod ChunkSize
  32.         ReDim Chunk(Fragment)
  33.         Get DataFile, , Chunk()
  34.         RS!logo.AppendChunk Chunk()
  35.         ReDim Chunk(ChunkSize)
  36.         For i = 1 To Chunks
  37.             Get DataFile, , Chunk()
  38.             RS!logo.AppendChunk Chunk()
  39.         Next i
  40.     Close DataFile
  41. End Sub
  42.  
Dec 4 '06 #1
0 30405

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

Similar topics

3
by: Hrvoje Voda | last post by:
How to insert a blob arraylist into database? I know it's not good, but my customers want that, so if someone has some simple example of how to do it... Hrcko
4
by: jack | last post by:
Hi. I wanted to save image from the form in my accss database. there is one picture box on form which loads the picture from the harddisk . i want this picture to store in my database .. thanks...
0
sashi
by: sashi | last post by:
BLOB - Retieve image stored in database Dim CN As New ADODB.Connection Dim RS As ADODB.Recordset Dim DataFile As Integer, Fl As Long, Chunks As Integer Dim Fragment As Integer, Chunk() As...
1
by: jamal8t2 | last post by:
i have inserted blob data in database , but i am not able to access back that data to the browser. i have php script but it does not work proprly. our script is below if ($_REQUEST == 1) { ...
0
by: hnpatel | last post by:
hello friends, i m making application in vb.NET. i m using MY SQL 5.0 and vs 2005 for this application. Now I want to save image file in sql database. i m using blob datatype of image field. i...
6
by: Jerry Spence1 | last post by:
I am using a network camera that saves the image in a byte array in memory (via their ocx component, and in the OnNewImage event I can get the pointer to the image and the byte length as...
1
ranjana1980
by: ranjana1980 | last post by:
In my project of desktop application using c#.net save image in database during registration of student But it is not mandatory.Without Browse the image i click on insert button it gives error "Empty...
2
by: rajeshkumarswain | last post by:
hi friends, I am new in php and i am trying to save image to database. Please provide a sample.
3
by: regan2007 | last post by:
How are you going to save image in database using php?Please explain it if you do kno
2
by: aznimah | last post by:
Hi, i need help on how to save the image that return from picturebox? basically the program works, 1)Read image (.png)--> load into pictureBox1 2)Fire button save to save the image from...
1
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.