Click here to Skip to main content
16,020,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I
C#
Private Sub cmdDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDel.Click
     
        If MessageBox.Show("Are you sure?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = Windows.Forms.DialogResult.No Then
            MsgBox("Record Deletion Opearation Cancelled")
            Exit Sub
        End If
        Try
            ''STR = "DELETE FROM StdMasterNew WHERE '" & TextBox1.Text & "'=ID"
            ''STR = "DELETE FROM StdMasterNew WHERE ID='" & TextBox1.Text & "'"
            STR = "DELETE FROM StdMasterNew WHERE ID= " & TextBox1.Text & ""
            CMD = New OleDbCommand(STR, CON)
            CON.Open()
            CMD.ExecuteNonQuery()
            CON.Close()
            Me.Refresh()
            MsgBox("Existing Record Updated Successfully...")
        Catch
            If CON.State = ConnectionState.Open Then
                CON.Close()
            End If
            MessageBox.Show("Error Deleting data...")
            'MsgBox(ex.Message & " -  " & ex.Source)
            'MessageBox.Show(ex.Message)
        End Try
        CON.Open()
        STR = "SELECT * FROM StdMasterNew"
        CMD = New OleDbCommand(STR, CON)
        CMD.ExecuteNonQuery()
        CON.Close()

        'Moving to Last Record
        CurrentRow = DST.Tables("ClassMan").Rows.Count - 1
        ShowData(CurrentRow)
    End Sub


This is my Delete button code. But When I press it the record gets deleted but showing when I press BACK, NEXT, FIRST, LAST buttons. But when I re-compile it the record is deleted

What I have tried:

i have tried refreshing with
Me.Refresh
but useless...
Posted
Updated 9-Apr-16 6:47am

1 solution

OK, so you deleted the record in the database but you didn't refresh the dataset your data controls is bound to to reflect the deleted record. Reload the data into the structure you've bound you controls to and the record will disappear.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900