我们的想法是,删除时选择的行将从datagridview,数据库中删除,然后datagridview将被刷新.我假设它必须使用SQL完成,但是如何将类型为text的sqlcommand与该特定行的删除代码相关联?数据库由一个表组成,数据网格绑定到该表.
删除按钮:
private void btnBookRecord_Click(object sender, EventArgs e)
{
if (this.BooksGrid.SelectedRows.Count > 0)
{
foreach (DataGridViewRow dgvrCurrent in BooksGrid.SelectedRows)
{
if (dgvrCurrent == BooksGrid.CurrentRow)
{
BooksGrid.CurrentCell = null;
}
// Delete row code here
}
}
}
Run Code Online (Sandbox Code Playgroud)