Feel the convenience of DataGrid to data operation (5)

xiaoxiao2021-03-06  79

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 ();

转载请注明原文地址:https://www.9cbs.com/read-92746.html

New Post(0)