DataGridView中的数据从数据库中删除后不能实时更新!

来源:百度知道 编辑:UC知道 时间:2024/07/03 01:16:45

Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
If DataGridView1.CurrentCell.RowIndex < -1 Then
Return
End If
Me.DataGridView1.Rows.RemoveAt(DataGridView1.CurrentCell.RowIndex)
End Sub
删除DataGridView1中记录,然后再更新数据库

先删除DataGridView中的数据再更新数据库这种做法本人认为不是很好

你可以做一个填充DataGridView的方法,用DataGridView的DataSource属性来给DataGridView赋值

然后更新数据库后重新调用这个填充DataGridView的方法旧可以了,这样做整体感觉比较好,代码可重用性高