472,783 Members | 1,040 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 472,783 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 30113

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...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.