Hi, i am doing with deleting row permenately from database currently,but the problem i face right is that i can delete row from datagridview only, but the data inside database remains unchange.I want to delete a row which i selected permenately when i click a delete button .

Here is the code that i written...

Private Sub Delete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Delete.Click

        conn_1.Open()
        Dim sqladapter_1 As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter("select * from Table_1", conn_1)
        sqladapter_1.Fill(sa, "Table_1")

        Dim cmb1 As New SqlClient.SqlCommandBuilder(sqladapter_1)
        For Each row As DataGridViewRow In DataGridView1.SelectedRows
            DataGridView1.Rows.Remove(row)

        Next
        DataGridView1.EndEdit()
        sqladapter_1.Update(sa, "Table_1")
        conn_1.Close()
    End Sub

what's the code i should added to get what i desired?

Private Sub Delete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Delete.Click

        conn_1.Open()
        Dim sqladapter_1 As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter("select * from Table_1", conn_1)
        sqladapter_1.Fill(sa, "Table_1")

        Dim cmb1 As New SqlClient.SqlCommandBuilder(sqladapter_1)
        For Each row As DataGridViewRow In DataGridView1.SelectedRows
              DataGridView1.Rows.Remove(row)
              sa.Tables("Table_1").Rows.Remove(row)
        Next
        sqladapter_1.Update(sa, "Table_1")
        conn_1.Close()
    End Sub

After i tried ur code,it comes out with this error "Value type of 'system.windows.form.datagridviewrow' cannot convert to 'system.data.datarow' "
However,i have changed my code succefully from internet resources and it works. The code was below:

Dim sqladapter_1 As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter("select * from Table_1", conn_1)
        sqladapter_1.Update(sa, "Table_1")
        For Each row As DataGridViewRow In DataGridView1.Rows

            If row.Selected = True Then
                Dim com As New SqlClient.SqlCommand
                com = New SqlClient.SqlCommand("delete_row", conn_1)
                com.CommandText = "delete from Table_1 Where " & "ID= " & row.DataBoundItem(1).ToString
                conn_1.Open()
                com.ExecuteNonQuery()
                conn_1.Close()
                sa.Tables(0).Rows.RemoveAt(row.Index)
                DataGridView1.DataSource = sa.Tables(0)
            End If

        Next

Thanks anyway...^^

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.