Dear All
In my windows form application I am unable to insert and retrieve photo in Picture box.
using my openfiledialog1 I can able to bring photo to picture box.Access database column name is photo
and type is oledb object
my codes are as below.
Button add Photo event
Private Sub btnAddphoto_Click(sender As Object, e As EventArgs) Handles btnAddphoto.Click
With OpenFileDialog1
.InitialDirectory = "C:\"
.Filter = "All Files|*.*|Bitmaps|*.bmp|GIFs|*.gif|JPEGs|*.jpg"
.FilterIndex = 2
End With
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
With PhotoPictureBox
.Image = Image.FromFile(Me.OpenFileDialog1.FileName)
.SizeMode = PictureBoxSizeMode.StretchImage
End With
End If
End SubForm Load event code
Private Sub Admission_Load(sender As Object, e As EventArgs) Handles MyBase.Load Try Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SMS.accdb")) Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM Registration", con) con.Open() da = New OleDb.OleDbDataAdapter(cmd) da.Fill(ds, "Table") MsgBox("Database is now Open") con.Close() MsgBox("Database is now Close") Catch ex As Exception MessageBox.Show("There was an Error processing your request. Please Try again." & vbCrLf & vbCrLf &"Original Error:" & vbCrLf & vbCrLf & ex.ToString, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try . . . . If IsDBNull((ds.Tables("Table").Rows(0).Item(7))) Then PhotoPictureBox.Image = Nothing Else PhotoPictureBox.Image = CType((ds.Tables("Table").Rows(0).Item(7)), Image) End If . . . . End Sub
my Commit button codes are
Private Sub btnCommit_Click(sender As Object, e As EventArgs) Handles btnCommit.Click If inc <> -1 Then Try Dim cb As New OleDb.OleDbCommandBuilder(da) Dim dsNewRow As DataRow dsNewRow = ds.Tables("Table").NewRow() . . . . dsNewRow.Item("Photo") = PhotoPictureBox.Image . . . .
ds.Tables("Table").Rows.Add(dsNewRow)
da.Update(ds, "Table")
End Sub
my Update button codes are
Private Sub btnUpdate_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click
Dim cb As New OleDb.OleDbCommandBuilder(da)
.
.
.
.
If IsDBNull("NULL") Then
PhotoPictureBox.Text = ""
Else
ds.Tables("Table").Rows(inc).Item(7) = PhotoPictureBox.Image
End If
.
.
.
.
da.Update(ds, "Table")
MessageBox.Show("Data updated")
End SubPl suggest the necessary step.
sunilsb