Guest benamar Posted February 2, 2009 Share Posted February 2, 2009 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 More sharing options...
Technage Posted February 27, 2009 Share Posted February 27, 2009 Can you give the error you are recieving this seems interesting. Is there a reason you are doing this in this way instead of some other way? I can think of way simpler methods. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.