C#控件中的DATAGRID中的删除按钮怎么写代码?
C#控件中的DATAGRID中的删除按钮怎么写代码?
------解决方案--------------------private void DataGrid1_DeleteCommand(object source, DataGridCommandEventArgs e)
{
SqlConnection cn = new SqlConnection( connectionString);
string strDelete = "delete from Note Where id = @id ";
SqlCommand cmd = new SqlCommand(strDelete, cn );
cmd.Parameters.Add( "@id ", SqlDbType.VarChar).Value = DataGridView.DataKeys[e.Item.ItemIndex].ToString();
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
DataGrid1.EditItemIndex = -1;
BindDataGrid();//重新绑定到数据库
}