troubleshooting Question

Removing records from a database via gridview using

Avatar of DJ P
DJ PFlag for United States of America asked on
DatabasesVisual Basic.NETWindows OSSQLMicrosoft Visual Studio
2 Comments1 Solution118 ViewsLast Modified:
I have a windows form I created in visual studio 2017, In the form I have a datagrid view called DataGridView1 the form connects to a sql database. The table that populates that database is called tbl_Supervisors and contains the following fields. Empl_ID (unique Primary Key) Last_Name, First_Name and so on. I created a button with the following code (see below) to remove a selected record or records from the grid. However, this does not removed the records from the database. I'm assuming I need something like SQL.ExecQuery("Delete From tbl_Supervisors where EMPL_ID=
but being a semi-newbie I don't know the proper syntax and where to place that line or lines of code in relation to my code below.

Private Sub cmdDeleteUser_Click(sender As Object, e As EventArgs) Handles cmdDeleteUser.Click
        If DataGridView1.SelectedRows.Count > 0 Then
            For i As Integer = DataGridView1.SelectedRows.Count - 1 To 0 Step -1

            MessageBox.Show("No rows to select")
        End If
    End Sub
End Class
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros