How Do I Update My DataGridView, After Deleting A Record in my SQL Database, with A Button on my form

Gary Simpson 451 Reputation points

Hello Good People,

I have a DataGridView called (DGVMultiRecords) and a Combo Box, When I select a value from the Combo Box, The DataGridView is populated with data I am searching for, The when I click on a record in the DataGridView. and I want to delete the selected row. I click a button called (CmdDelete)

This is where I have an issue, The record is deleted, But the DataGridView does not update after Deletion, But when I close the form and reload the record is not there it has been deleted. I have tried remove current, this is where I get an error message. Picture and Code Below.

Can any of you good People Help me please

Kind Regards


Delete Error

Private Sub CmdDelete_Click(sender As Object, e As EventArgs) Handles CmdDelete.Click

        Dim Dialog As DialogResult

        Dialog = MessageBox.Show("Are You sure you want to Delete this record Permanently",
                                 FrmMenu.LbMemberName.Text, MessageBoxButtons.YesNo)

        If Dialog = Windows.Forms.DialogResult.No Then
            'Do Nothing
            MsgBox(FrmMenu.LbMemberName.Text & ", You Have Selected NOT to Delete This Record",
                   MsgBoxStyle.Information, "Record is Safe")
        End If

        If Dialog = Windows.Forms.DialogResult.Yes Then

            MsgBox("Record Deleted ", MsgBoxStyle.Information, FrmMenu.LbMemberName.Text & ",  Deleted Successfully")




            'DGVMultiRecords.DataSource = SQL.SQLDT

        End If

    End Sub

    Private Sub DeleteFromMultiRecords()
        SQL.RunQuery("SELECT * FROM MultiRecords ")
        If SQL.RecordCount < 1 Then
            MsgBox("There are no records to delete ", MsgBoxStyle.Exclamation, "No Records In Your Database (Multi Records)")
            Exit Sub

            SQL.AddParam("@MultiDropID", LbMultiDropID.Text)

            SQL.ExecQuery("DELETE " &
                          "FROM MultiRecords " &
                          "WHERE MultiDropID=@MultiDropID ")

            If SQL.HasException(True) Then Exit Sub

            'Dim DGV As DataGridViewRow = DGVMultiRecords.SelectedRows(0)


            'DGVMultiRecords.DataSource = DGV

        End If
    End Sub
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
9,860 questions
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,108 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 14,216 Reputation points Microsoft Vendor

    Hi @Gary Simpson ,

    You can requery the database data and populate your DataGridView after deletion.

    Just take part of the code that queries and populates the Datagridview as a method and call it again.

    Best Regards.

    Jiachen Li

    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful