Place a DataGrid on the form and populate it, now double click the dataGrid and use the below code.
private void DataGridvie_selected(Object sender, EventArgs e) { DataSet da = new DataSet(); //when you select a row that index will storing in i variable int j = datagrid1.selectedIndex; int empidval = ds.Tables["emp"].Rows[j][0].ToString(); //above what you had selected that row value exa:empid has 101 is stored in empidval vairable //write the delete query SqlConnection conn = new Sqlconnection("conn string"); conn.Open(); SqlCommand cmd = new SqlCommand("delect emp where empid=" + empid + "", conn); cmd.ExecuteNonQuery(); MessageBox.Show("Row Deleted"); }
0 comments:
Post a Comment