从Access数据库vb.net中删除记录
在这个项目中,我使用DataGridView中显示的Access数据库。我正在尝试删除acces行,但我的查找未成功 从DataGridView中删除记录的代码:从Access数据库vb.net中删除记录,vb.net,ms-access,vb.net-2010,Vb.net,Ms Access,Vb.net 2010,在这个项目中,我使用DataGridView中显示的Access数据库。我正在尝试删除acces行,但我的查找未成功 从DataGridView中删除记录的代码: Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick Dim index As Integer index
Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
Dim index As Integer
index = DataGridView1.CurrentCell.RowIndex
DataGridView1.Rows.RemoveAt(index)
ZoznamBindingSource.RemoveCurrent().
‘Dim da As OledbDataAdapter
‘Dim ds As dataSet
da.Update(ds)
End Sub
最后一行代码给了我一个错误:SystemNullReferenceException。我知道数据集是个问题,但我不知道用哪个代码来替换它
任何解决方案?BindingSource的要点在于它是绑定数据的唯一联系点。您不必触摸UI,也不必触摸数据源
在您的情况下,应该在
BindingSource
上调用RemoveCurrent
。这将把底层的DataRow
标记为Deleted
,然后,当您在数据适配器上调用Update
时,相应的数据库记录将被删除。您是如何绑定数据网格视图的?BindingSource,直接到表/数据集?生成DataGridView行?我使用BindingSource我使用RemoveCurrent(),当我更新dataadapter时,我得到一个错误的系统空引用Exception@Lasicak,然后您做了一些错误的事情,但是您没有解释您做了什么,也没有向我们显示相关代码,因此我们可能无法帮助您解决该问题。如果您还没有访问过该网站,请访问该网站,并花一些时间在帮助中心了解该网站的工作原理。不足为奇的是,其中的一部分是提供有关您需要帮助的问题的所有相关信息。不要在答案中发布未格式化的代码,并期望发生任何有用的事情。所有与问题相关的信息都应包含在问题中,格式应适当。任何人都不必阅读对问题的评论,更不用说回答了,才能理解问题。如果你原来没有提供的信息很明显是相关的,请编辑问题以提供它。对不起,很高兴知道。现在,我的问题已用问题代码编辑。