c# 如何删除datagrieview中指定那行数据

来源:百度知道 编辑:UC知道 时间:2024/06/23 14:55:14
不按主键查询的话,查出来的数据是很多条~

那么多条数据,删除指定的一条~思路是怎样?

string id = this.dataGridView1.CurrentRow.Cells["id"].Value.ToString();
id是数据库中的主键,然后在数据库中用SQL删除。在Datagridview表中清除是
this.dataGridView1.Rows.Remove(this.dataGridView1.CurrentRow);这样就可以了。

删除选中一条的方法:
dataGridView1.Rows[dataGridView1.SelectedCells[0].RowIndex].Cells[0].Value.ToString().Trim();

循环获取行主键,再进行删除。