Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 使用datagridview从数据库中永久删除行_Vb.net_Winforms - Fatal编程技术网

Vb.net 使用datagridview从数据库中永久删除行

Vb.net 使用datagridview从数据库中永久删除行,vb.net,winforms,Vb.net,Winforms,在VB.net中,如何通过在datagridview中选择并使用按钮删除从数据库中永久删除行 我尝试使用DataGrid.Rows.Remove,但它只从DataGrid而不是数据库中删除 我使用的是SQL Server数据库,没有更多的代码,这很困难,但通常网格与数据源关联。数据源具有deletequery的属性 样本来自: 记录删除时的子项(ByVal源作为对象,ByVal e作为SqlDataSourceCommandEventArgs) '如果未选中该复选框,则取消删除操作。 如果未选

在VB.net中,如何通过在datagridview中选择并使用按钮删除从数据库中永久删除行

我尝试使用DataGrid.Rows.Remove,但它只从DataGrid而不是数据库中删除


我使用的是SQL Server数据库

,没有更多的代码,这很困难,但通常网格与数据源关联。数据源具有deletequery的属性

样本来自:


记录删除时的子项(ByVal源作为对象,ByVal e作为SqlDataSourceCommandEventArgs)
'如果未选中该复选框,则取消删除操作。
如果未选中复选框1。选中
e、 取消=真
Label1.Text=“由于未选中复选框,命令被取消。”
如果结束
记录上的结束子项删除
已删除记录上的子项(ByVal源作为对象,ByVal e作为SqlDataSourcestatuseEventArgs)
Label1.Text=e.AffectedRows&“行已删除”
端接头
ASP.NET示例




根据您的原始帖子和后续评论,我假设您的表单看起来像

如果是这种情况,您可以在不添加代码的情况下永久删除。其工作方式是允许您编辑、删除和添加多行。默认情况下,它有一个备份数据集,并且具有更改跟踪功能。完成后,单击保存图标,它会将更改提交到数据库

如果您已经为此添加了自己的接口,那么您必须查看生成的控件,以了解如何操作。您使用的方法将在其他项中创建备份
数据集
数据适配器
数据表

' You should have a binding source - I used a table called PointsOfInterest
Me.PointsOfInterestBindingSource.EndEdit()  ' changes that have been tracked will be applied to the datasource
Me.TableAdapterManager.UpdateAll(Me.Your_DataSet)

这应该会将您的更改提交回数据库。

您真的在使用DataGrid而不是DataGridView吗?这是Winforms吗?数据是如何进入控件的?需要更多的信息是的,很抱歉,我使用的是DataGridViews,它是win Form,然后您的帖子提供了正确的信息。事实上,它误导人们给出错误的答案,就像贴出的答案一样。让别人更容易帮助你。还要解释一下数据是如何进入控件的。我不明白你所说的“控件”是什么意思。我使用Add Data SourceDataGridView从我的SQL Server在项目中添加了数据库。DataGridView是WinForm控件。@Han DataSource控件在web和win表单中很常见。我可以删除webgrid的源代码,但它只是用来展示实现。非常感谢。它解决了这个问题。
' You should have a binding source - I used a table called PointsOfInterest
Me.PointsOfInterestBindingSource.EndEdit()  ' changes that have been tracked will be applied to the datasource
Me.TableAdapterManager.UpdateAll(Me.Your_DataSet)