Jump to content

Problem When Deleting Rows Using Dataset C#


Guest benamar

Recommended Posts

Guest benamar

hi everybody , need help for this problem please .I have a table and I want to delete row . when I delete just 1 row it works ,but whene I want to delete 2 or more rows who has the same "adress" that handle an exception but it delete even though .this is my code : SqlConnection conn = new SqlConnection("data source=pc-s5;initial catalog=benamar;integrated security=true"); conn.Open(); SqlDataAdapter adpt = new SqlDataAdapter(); adpt.SelectCommand = new SqlCommand("select * from etudiant",conn); DataSet ds = new DataSet(); adpt.Fill(ds,"etudiant2"); DataTable dt =ds.Tables["etudiant2"]; SqlCommand cmd=new SqlCommand("delete from etudiant where adress=@adress1",conn); cmd.Parameters.Add(@"adress1",SqlDbType.VarChar,10,"adress"); string st = "adress=" +"'"+ textBox6.Text+"'"; foreach (DataRow ROW in dt.Select(st)) { ROW.Delete(); } adpt.DeleteCommand = cmd; adpt.Update(ds,"etudiant2"); // the exception handle at this point thanks .

Link to comment
Share on other sites

  • 4 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...