I am stuck with how to save an image path to my database please could anyone help. I have a picture box and a file dialogue. I select a picture which appears on the picture box the I like to save its path to my database while saving the picture to a folder.
System Configuration: Windows 7 / Internet Explorer 9.0
How to store image in ms access
How to insert image in access database form - Best answers
How to insert image in ms access database table - Best answers
I have designed this small application for you that might suite your need. This application has an Open Button which will help you open any picture file to a PictureBox on the form using OpenFileDialog. You will see the path of the picture file in a disabled TextBox. When you click the update button the Picture's path is saved to an Access Database.
Follow the steps below to create a similar project for yourself:
1. Create a new Visual Basic .net project. Select Windows Forms Application from New Project Dialog Box. Name this application as mikeoe2003PictureApplication.
2. Create the following with below mentioned properties:
a. Form - (Name): mikeoe2003PictureApplication, Text: FormPictureApplication
b. PictureBox - (Name): PictureBox1, SizeMode: StretchImage
c. Button - (Name): ButtonUpdate, Text: &Update
d. Button - (Name): ButtonOpen, Text: &Open
e. TextBoxt - (Name): TextBoxPictureFilePath, Enabled: False
3. Double Click the Form, insert the following code right above Public Class mikeoe2003PictureApplication:
Catch Ex As Exception
MessageBox.Show("Cannot read file from disk. Original error: " & Ex.Message)
If (myStream IsNot Nothing) Then
4. Create a Microsoft Access Database in your convenient location and name it as Databasemikeoe2003PictureApplication.mdb
5. Create a table with the name Tablemikeoe2003PictureApplication and add following Columns to it:
Id - Datatype: Autonumber
PicturePath - DataType: Memo (as file paths can be considerably long at times)
6. Double Click the UpdateButton and insert the following code:
Dim myConnection As OleDbConnection
Dim myCommand As OleDbCommand
Dim mySQLString As String
myConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Databasemikeoe2003PictureApplication.mdb;")
mySQLString = "INSERT INTO Tablemikeoe2003PictureApplication (PicturePath) VALUES('" & Replace$(TextBoxPictureFilePath.Text, "'", "''") & "')"
myCommand = New OleDbCommand(mySQLString, myConnection)