//删除,行删除
private void 删除_Click(object sender, EventArgs e)
{ int dgrcount = dataGridView1.SelectedRows.Count;
if (dgrcount>)
{
string selectedRowName=dataGridView1.SelectedRows[].Cells[].Value.ToString();//获取选中的行的用户名 string cmdText = "delete from tb_admin where 用户名='" + selectedRowName + "'";//构建删除行语句
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=ErLake.mdb";
OleDbCommand cmd = new OleDbCommand(cmdText, conn);
conn.Open();
//逐行删除
foreach (DataGridViewRow dgvRow in dataGridView1.SelectedRows)
{ dataGridView1.Rows.Remove(dgvRow);//删除dataGridView中的数据
cmd.ExecuteNonQuery();//删除数据库表中的数据
}
conn.Close(); } }