|
hi
how to delete rows from grid? & also how to display selected cells on labels?
when I select perticular row to delete then row is deleted from database but in gride view all rows are disappeared even through data is still there in database.
private void btnDelete_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(" Data Source=VINOD-AD973EE47\\SQLEXPRESS;Initial Catalog=FIS;Integrated Security=True"); con.Open(); string sql = "Select * From ProductBOM "; SqlCommand cmd = new SqlCommand(sql, con); childID = Convert.ToInt32(gridBOM.SelectedCells[0].OwningRow.Cells[0].Value.ToString()); cmd.CommandText = "Delete From ProductBOM Where Id="+ childID +""; //DataSet dsdata = new DataSet(); con.Close(); SqlDataAdapter mydataAdapter = new SqlDataAdapter(cmd); mydataAdapter.Fill(dataset, "ProductBOM"); gridBOM.DataSource = dataset.Tables[0].DefaultView; MessageBox.Show("Item Deleted");
try { childID = GetChildId(); if (childID > 0) {
DataColumn[] dc = new DataColumn[1]; dc[0] =dataset.Tables[0].Columns[0]; dataset.Tables[0].PrimaryKey = dc; DataRow dr =dataset.Tables[0].Rows.Find(childID.ToString()); if (dr != null) { dataset.Tables[0].Rows.Remove(dr); } } } catch (SqlException sexception) { if (sexception.Message.Equals("Unitused")) { Utility.ShowErrorMessage("Unitused"); } else { Utility.ShowExceptionMessage(sexception.Message); } } catch (Exception ex) { Utility.ShowExceptionMessage(ex.Message); } }
This post has been edited by mamta takarkhede: 30 Jun, 2008 - 11:30 AM
|