如何在datagridview中编辑/删除数据? [英] how to edit/delete data in a datagridview?

查看:270
本文介绍了如何在datagridview中编辑/删除数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此代码使用VB.NET和SQL删除datagridview中的记录-12



Im using this code for the deleting of records in a datagridview using VB.NET and SQL -12

Private Sub Delete_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Delete.Click
    If MessageBox.Show("delete this item?", "DELETE!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = Windows.Forms.DialogResult.Yes Then
        Me.DataGridView.Rows.RemoveAt(Me.DataGridView.CurrentRow.)
    Else
        DataGridView.Update()
    End If
End Sub



当我使用它时,记录只会被临时删除但不会永久删除数据库。我该如何永久删除记录?我编辑字段的情况也是如此。它只是临时的


When Im using this, the record only gets deleted temporarily but not permanently from the database. How should I delete the records permanently? The same is the case when I'm editing a field. It's just temporary

推荐答案

我的猜测是你有一个支持DataGridView的DataTable和DataAdapter,你需要从DataTable中删除并更新DataAdapter。 DataGridView只是DataTable中的内容的一个视图。
My guess is that you have a DataTable and a DataAdapter backing the DataGridView and you need to delete from the DataTable and Update the DataAdapter. A DataGridView is just a view of what's in the DataTable.


一旦从DataGridView中删除一行,您将需要编写一个查询来更新数据库。
You will need to write a query to update the database once you delete a row from the DataGridView.


这篇关于如何在datagridview中编辑/删除数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆