单击鼠标选中数据
我想删除GridView中单击选中的行,下面的代码对吗?为什么每次删除的都不是选中的行?
private static int rowIndex = 1;
private void Data_GridView_CellEnter(object sender, DataGridViewCellEventArgs e)
{
rowIndex = e.RowIndex;
//Data_GridView.
}
int i = rowIndex;
private void btn_dele_Click(object sender, EventArgs e)
{
try
{
SqlDataAdapter myDataAdapter = new SqlDataAdapter(sql, conn);
SqlCommandBuilder myBuillder = new SqlCommandBuilder(myDataAdapter);
DataRow drow = myDataSet.Tables["Mark"].Rows[i];
drow.Delete();
myDataAdapter.Update(myDataSet, "Mark");
conn.Close();
Console.ReadLine();
}
catch
{
}
}