如何从VB.NET中的datagridview和Access数据库中删除行? [英] How to delete row from datagridview in VB.NET and from access database?

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

问题描述

我想从vb.net中的datagridview和access数据库中删除行而不将数据附加到textbox意味着从datagrid选择行并单击delete opertaion。



我尝试过:



如果DataGridView1.SelectedRows.Count> 0然后



'标签lblID =(标签)dataGridView1.SelectedRows [0] .FindControl(lblPrimaryKey);

'SqlCommand cmd = new SqlCommand(从表中删除id ='+ Convert.ToInt32(lblID.Text)+',ConnectionObject);

'cmd.ExecutenonQuery();

'结束如果

I want to delete row from datagridview in vb.net and from access database without appending data to textbox means on select row from datagrid and click delete opertaion.

What I have tried:

If DataGridView1.SelectedRows.Count > 0 Then

'Label lblID= (Label) dataGridView1.SelectedRows[0].FindControl("lblPrimaryKey");
'SqlCommand cmd = new SqlCommand ("Delete from table where id='"+ Convert.ToInt32(lblID.Text)+"'",ConnectionObject);
'cmd.ExecutenonQuery();
' End If

推荐答案

如果我的假设是正确的,那么数据会从数据库中删除但仍然可以在DataGridView中看到,那么我建议你要么:

1)重新运行填充你的视图的查询(Datasource)最初

2)从用于DataGridView的数据源中删除已删除的项目



希望这有助于
If my assumption is correct, that data is deleted from the database but still is visible in your DataGridView, then I would suggest that you either:
1) rerun the query that filled your view (Datasource) initially
2) remove the deleted item from the datasource used for the DataGridView

Hope this helps


这篇关于如何从VB.NET中的datagridview和Access数据库中删除行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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