Section 5: Delete entries
It is simple to delete the entry for updated data relative to the fourth quarter. Key steps are as follows:
Add a deleted button column, how to add to the fourth quarter.
Set the DataGrid's DataKeyField property, you must be set to the keyword.
Add a DeleteCommand event, write code:
public void MyDataGrid_Delete (Object sender, DataGridCommandEventArgs e) {String deleteCmd = "DELETE from Employee where emp_id = @Id"; SqlCommand myCommand = new SqlCommand (deleteCmd, myConnection); myCommand.Parameters.Add (new SqlParameter ( "@ Id", Sqldbtype.nvarchar, 11)); mycommand.parameters ["@ id"]. Value = mydatagrid.datakeys [it); mycommand.Connection.Open (); try {mycommand.executenon query (); } catch (sqlexception) {} mycommand.connection.close (); bindgrid ();