将数据绑定到组件1 true dbgrid并使用delete键删除行 [英] Bind data to Component 1 true dbgrid and delete a row using delete key
问题描述
目前我正在使用datasource属性将数据集绑定到Component 1 true dbgrid。我想要以编程方式以类似的方式绑定它。
一旦数据绑定到网格,我将选择行并按下删除键,它必须从数据库和网格中删除该行。目前我启用了允许删除选项,该选项从网格中删除行而不是从数据库中删除。
请建议步骤,以便我可以将数据绑定到组件1编程为真正的dbgrid并使用删除键删除一行。
提前感谢。
Hi,
Currently i am binding the dataset to Component 1 true dbgrid using datasource property.I want the steps to bind it in similar way programmatically.
Once the data is bound to the grid i will select the row and press on delete key and it has to delete the row from the database and also from the grid. Currently i enabled Allow delete option which is deleting the row from the grid but not from the database.
Please Suggest the steps so that i can bind the data to the Component 1 true dbgrid programatically and delete a row using delete key.
thanks in advance.
推荐答案
方法如下:
假设绑定gridview时所有行都包含Id(表示主键)
创建一个查询以从db中删除表中的行当你点击删除按钮时接受一个ID
你可以得到这样的id:
datagridview1.CurrentRow.Cells [Id]。Value.ToString());
然后将上面的id传递给查询
然后从db
The method is as follows:
Assuming that when you bind the gridview all rows contains an Id (means primary key)
create a query to delete a row from table in db by accepting a Id
while you click on the delete button
you can get the id as:
datagridview1.CurrentRow.Cells["Id"].Value.ToString());
then pass the above id to the query
then rebound the datagrid from db
这篇关于将数据绑定到组件1 true dbgrid并使用delete键删除行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!