Cant Updating picture as OLE object, but save as new record works

RoyLittle0

Active member
Joined
Nov 17, 2012
Messages
38
Location
Derby, Uk
Programming Experience
Beginner
HI,

I have a access 2010 database linked to my VB.NET form, it has been done through databinding and is mainly through the wizard, I have a picture that is databound to my database through a OLE Object and I can add a picture and save it to a new record, but I cant update it through the same controls.

I am using an openfiledialog box to retrieve my picture and insert it into my form and I can view it there, when i hit the save button I get a message that says record saved and the picture disappears

I have added a picture so that you can see how i have bound my picture box and what controls i am using to get my database
CCImage.jpg

VB.NET:
Public Class Products


    Private Sub ProductsBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProductsBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.ProductsBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.CCDatabaseDataSet)


    End Sub


    Private Sub Products_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'CCDatabaseDataSet.Products' table. You can move, or remove it, as needed.
        Me.ProductsTableAdapter.Fill(Me.CCDatabaseDataSet.Products)
        btnUpdatePicture1.Visible = False
        btnAddNew.Visible = False
        btnDelete.Visible = False
        btnSaveDb.Visible = False
    End Sub


    Private Sub PictureBox2_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.DoubleClick
        If btnAddNew.Visible = False Then
            btnUpdatePicture1.Visible = True
            btnAddNew.Visible = True
            btnDelete.Visible = True
            btnSaveDb.Visible = True
        ElseIf btnAddNew.Visible = True Then
            btnUpdatePicture1.Visible = False
            btnAddNew.Visible = False
            btnDelete.Visible = False
            btnSaveDb.Visible = False
        End If
    End Sub


    Private Sub btnUpdatePicture1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdatePicture1.Click
        OpenFileDialog1.FileName = Nothing
        OpenFileDialog1.ShowDialog()
        If Not OpenFileDialog1.FileName = Nothing Then
            PictureBox1.ImageLocation = OpenFileDialog1.FileName
        End If
    End Sub


    Private Sub btnFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFirst.Click
        ProductsBindingSource.MoveFirst()
    End Sub


    Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
        ProductsBindingSource.MovePrevious()
    End Sub


    Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
        ProductsBindingSource.MoveNext()
    End Sub


    Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLast.Click
        ProductsBindingSource.MoveLast()
    End Sub


    Private Sub btnSaveDb_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveDb.Click
        Try
            Me.Validate()
            Me.ProductsBindingSource.EndEdit()
            Me.TableAdapterManager.UpdateAll(Me.CCDatabaseDataSet)
            MessageBox.Show("Update Successful")
        Catch ex As Exception
            MessageBox.Show(ex.Message & " - " & ex.Source)
        End Try


    End Sub


    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        If MsgBox("Are You Sure", MsgBoxStyle.YesNo, Title:="Confirm") = vbYes Then
            Me.ProductsBindingSource.RemoveCurrent()
            Me.Validate()
            Me.ProductsBindingSource.EndEdit()
            Me.TableAdapterManager.UpdateAll(CCDatabaseDataSet)
        End If
    End Sub


    Private Sub btnAddNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddNew.Click
        Me.ProductsBindingSource.AddNew()
    End Sub
End Class
 
Back
Top