473,396 Members | 1,707 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,396 software developers and data experts.

Save image in database

can you teach me how to convert to binary the picture in a picture box in order to save and retrieve to database acces ? help me plsss
Jul 30 '07 #1
2 1700
Killer42
8,435 Expert 8TB
can you teach me how to convert to binary the picture in a picture box in order to save and retrieve to database acces ?
Just have a look in the index of VB articles, at the top of the forum. There are a couple of entries there about storing and retrieving images in BLOBs, which are large binary database fields (Binary Large OBject, I believe).
Jul 30 '07 #2
To store an image from a file use this -
Expand|Select|Wrap|Line Numbers
  1. Dim cn As ADODB.Connection, rs As ADODB.Recordset, SQL As String
  2. Dim ps As New ADODB.Stream
  3. ps.Type = adTypeBinary
  4.  
  5. Set cn = New ADODB.Connection
  6. Set rs = New ADODB.Recordset
  7. cn.CursorLocation = adUseServer
  8. cn.Open "dsn=SQLDatabase"
  9.  
  10. SQL = "SELECT * FROM Student WHERE Student_ID = " & 1002
  11. rs.Open SQL, cn, adOpenStatic, adLockOptimistic
  12. 'rs.addnew
  13. ps.Open
  14. ps.LoadFromFile "C:\My Documents\My Pictures\Student1002.JPG"
  15. rs!Student_Photo = ps.Read
  16. rs.Update
Note - this uses the streaming object so you need a reference to ADO (MS Data ActiveX Data Objects) 2.6 or greater
To read it back out to a file that you can then reference as the source for a picture control -
Expand|Select|Wrap|Line Numbers
  1. Dim cn As ADODB.Connection
  2. Dim rs As ADODB.Recordset
  3. Dim ps As New ADODB.Stream
  4. Dim SQL As String
  5.  
  6. ps.Type = adTypeBinary
  7. Set cn = New ADODB.Connection
  8. Set rs = New ADODB.Recordset
  9.  
  10. cn.CursorLocation = adUseServer
  11. cn.Open "dsn=SQL Database"
  12.  
  13. SQL = "SELECT * FROM Student WHERE Student_ID = " & Me.txtStudent_ID
  14. rs.Open SQL, cn, adOpenStatic, adLockReadOnly
  15. ps.Open
  16.  
  17. ps.Write rs!Student_Photo
  18. ps.SaveToFile "C:\Student_Photo.JPG", adSaveCreateOverWrite
Jul 30 '07 #3

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

Similar topics

1
by: Sam Martin | last post by:
Hi all, got a problem when converting a PNG to a JPG using the Image.Save(stream, format) method. When I save the original PNG to a file and open it, it's fine. I then save it to a database,...
2
by: Corobori | last post by:
I am getting an error message "Description: Value cannot be null. Parameter name: encoder" when performing this instruction: frmPicView.pic.Image.Save(ms, frmPicView.pic.Image.RawFormat) Here is...
9
by: DapDap | last post by:
I have manage to open a image into a picture box. But I have problem in Saving it into database SQL Server. How to save the image ??
1
by: Ishtiaque Ahmed Memon | last post by:
Dear All Can anyone tell me how to save an JPEG image in a database table field? Below is the code that I have wrote but it gives an error: System.InvalidCastException Object must implement...
1
by: ankz | last post by:
Hi Guys I have got 3 tables - in Access Database with Student ID as primary Key in all and all tables are linked with 1 to 1 relationship. I have code the everying with manual program to...
1
by: Smita Kashyap | last post by:
Hello to all, Which one is flexible/optimal solution to save uplaoded image. Frist save image at server or from where you're site pages are save in any image folder and save only image name or...
3
by: =?Utf-8?B?Um9nZWxpbw==?= | last post by:
I'm having the wierdest problem. I'm trying to save images into a SQL 2005 database. the field is just called "IMAGES" and hte data type is "image". here is my code to save //following code...
4
by: Logician | last post by:
I am running on my PC Windows Forms to collect data from websites, including images. I hit a problem with images and javascript, and I would appreciate any help. The current code fails with a...
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...
8
by: anandmms | last post by:
Hello friend, my problem is to save more than one fingerprint images in one byte array and then store in database(oracle). i dont know how to solve it. But previously i had did image saving...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
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,...

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.