473,500 Members | 1,943 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

BLOB - Save image to database

sashi
1,754 Recognized Expert Top Contributor
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 30433

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

Similar topics

3
1833
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
8717
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
23068
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
8213
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
2480
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
4009
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
2846
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
9642
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
2004
by: regan2007 | last post by:
How are you going to save image in database using php?Please explain it if you do kno
2
7427
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
7018
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7182
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,...
1
6906
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7397
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5490
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4923
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4611
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1430
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
672
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.