ramesh rammi

ramesh rammi

  • NA
  • 86
  • 14k

row delete can't be effect on database

Mar 31 2018 5:07 AM
My code worked properly but row can't be delete from database table.in datatable row deleted.after call the .da.update(ds,"student") need to effected database table but row can't be deleted in database table
 
my code:
  1. SqlConnection con = new SqlConnection("Data Source=AMMA-PC\\SQLEXPRESS;Initial Catalog=E_learn;Integrated Security=True");  
  2. string query="select * from Student where sid="+TextBox1.Text;  
  3. SqlDataAdapter da = new SqlDataAdapter(query, con);  
  4. SqlCommandBuilder br = new SqlCommandBuilder(da);  
  5. DataSet ds = new DataSet();  
  6. da.Fill(ds, "Student");  
  7. if (ds.Tables[0].Rows.Count > 0)  
  8. {  
  9. DataTable dt = ds.Tables[0];  
  10. DataColumn[] keyColumns = new DataColumn[1];  
  11. keyColumns[0] = dt.Columns["sid"];  
  12. dt.PrimaryKey = keyColumns;  
  13. DataRow dr = dt.Rows[0];  
  14. dt.Rows.Remove(dr);  
  15. da.Update(ds, "Student");  
  16. Response.Write("deleted successfully");  
  17. }  
I think u have doubt about delete row. how should know row deleted from datatable in dataset. i had verfied through breaking points keys like F10,F11.at the time in dataset visualizer shows before call da.update(ds,"Student") i have row. after call da.update(ds,"Student").dataset visualizer shows row deleted but database does not effected.row can't be deleted from database . what is the problem
 
i don't know. please help me.
Thank u

Answers (4)