Hi, im using vb2010 with MS Access 2013. I have this form that displays ID values from database into a listbox And when an ID is clicked the details that correspond with that ID are displyed into textboxes.

Screenshots :

Forms : http://imgur.com/a/NrTTD
Display details : http://imgur.com/a/twF7P

The delete button does delete the data from database but im having trouble with the form as when the data is deleted the "deleted" data is still displayed on the form. How do i refresh the forms so it does not display the deleted data after deletion?

Delete Button

Private Sub btn_delete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_delete.Click
        Dim delete_confirmation = MsgBox("Are you sure you would like to delete the product '" & txt_pname.Text & "' with ID '" & txt_pid.Text & "'?", MsgBoxStyle.YesNo)

        If delete_confirmation = MsgBoxResult.Yes Then

            Dim deleteproduct As String = "DELETE FROM TBL_PRODUCTS_A154287 WHERE FLD_PRODUCT_ID = '" & txt_pid.Text & "'"
            Dim mywriter As New OleDb.OleDbCommand(deleteproduct, myconnection2)


            Dim msgbx As String = MsgBox("The product '" & txt_pname.Text & "' has been successfully deleted.")

        End If

        End If
    End Sub

Cat Button (Display Cat details)

Private Sub btn_cat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_cat.Click
        Dim getProduct As String = "SELECT FLD_PRODUCT_ID,FLD_TYPE FROM TBL_PRODUCTS_A154287 WHERE FLD_TYPE = 'Cat'"

        Dim theTable As New DataTable

        Dim reader As New OleDb.OleDbDataAdapter(getProduct, myconnection)


        lst_product.DataSource = theTable
        lst_product.DisplayMember = "FLD_PRODUCT_ID"

        btn_edit.Enabled = True
        btn_update.Enabled = True
        btn_delete.Enabled = True
End Sub

refresh_text code

Private Sub refresh_text(ByVal id As String)

        Dim getID As String = "SELECT * FROM TBL_PRODUCTS_A154287 WHERE FLD_PRODUCT_ID='" & id & "'"
        Dim theTable As New DataTable
        Dim reader As New OleDb.OleDbDataAdapter(getID, myconnection)


        txt_pid.Text = theTable.Rows(0).Item("FLD_PRODUCT_ID")
        txt_pname.Text = theTable.Rows(0).Item("FLD_PRODUCT_NAME")
        txt_brand.Text = theTable.Rows(0).Item("FLD_BRAND")
        txt_desc.Text = theTable.Rows(0).Item("FLD_DESC")
        txt_price.Text = theTable.Rows(0).Item("FLD_PRICE")
        txt_qty.Text = theTable.Rows(0).Item("FLD_QTY")

            pic_img.BackgroundImage = Image.FromFile("pictures/" & txt_pid.Text & ".jpg")
        Catch ex As Exception
            pic_img.BackgroundImage = Image.FromFile("pictures/nophoto.jpeg")
        End Try

    End Sub

Edited 3 Weeks Ago by nadiam: wrong link

You can add a few lines in your codes in refresh_text subprocedure when id is null or whitespace, where you can nothing values to all textboxes and image control.

  1. (sugestion) Move connection close inside "If delete_confirmation = MsgBoxResult.Yes Then"

  2. After delete, just clear out your textboxes


This question has already been answered. Start a new discussion instead.