473,791 Members | 3,071 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Save image in database

3 New Member
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 1719
Killer42
8,435 Recognized Expert Expert
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
kentgorrell
11 New Member
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
4497
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, retrieve it and Save it as a JPG format and most of the image is fine except a large black band at the bottom of the image. What can i do?
2
2726
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 the code: what I am doing is scanning a document and try to get it from the form where I am previewing it directly to the database Private Sub PicTwainPro1_PostScandotNet(ByVal classPtr As Integer, ByVal objID As Integer, ByVal Cancel As...
9
2159
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
1027
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 IConvertible DatabaseAccess.SqlConnection.Open()
1
2928
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 access information of tables on Windows Form. It is working properly. i can see all the records properly.
1
2833
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 link to database. Secondly convert image to bite form then save whole bite form image to database. My friends feel that second one is right choice, but i felt that frist one is correct as conversion procedure and retrival from database is...
3
4400
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 saves an image as a byte array to a DB string strFn = this.openFileDialog1.FileName; this.pictureBox1.Image = Image.FromFile(strFn); FileInfo fiImage = new FileInfo(strFn); m_lImageFileLength = fiImage.Length;
4
6146
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 copy error. My Internet connected PC is not the development machine, so I cannot debug on that PC and my other PC has no Internet connection. So I cannot debug using .NET as normal.
0
2557
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 want to save image file from vb.net form. i m getting image in picturecontrol through openfiledialogbox. now how to save this image in my database through insert query? Plz help me for this..... Thanx in advance.....
8
10153
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 using byte array, but i want to know how to save more than one images in one database field.... actually i convert one image to byte array using the below code pb1 = picturebox1 pb2 = picturebox2
0
9669
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9515
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10207
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9995
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4110
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 we have to send another system
2
3718
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.