Suppresion a partir dun code c#

kaoutarac Messages postés 26 Date d'inscription mercredi 15 décembre 2010 Statut Membre Dernière intervention 6 septembre 2012 - 14 avril 2011 à 17:56
cs_Megafan Messages postés 389 Date d'inscription dimanche 7 avril 2002 Statut Membre Dernière intervention 23 septembre 2016 - 17 avril 2011 à 09:20
bonjour
je veux supprimer des donnees de type datatime a partir d'un programme c# mais le probleme c est que apres l'execusion le programme m affiche que les donnes sont supprime en revanche rien n a ete change au niveau de la base donne j ai toujours les donnes comprises entre l intrevale du temps
pouvez vous m aidez dans ce problem je suis bloque
mon code est le suivant
 private void Delete_Click(object sender, EventArgs e)
        {
            
           
            try
            {
               
             DateTime D1 = Convert.ToDateTime(yearstart.Text + "/" + monthstart.Text + "/" + daystart.Text + " 00:00:00.000");
               
             DateTime D2 = Convert.ToDateTime(yearend.Text + "/" + monthend.Text + "/" + dayend.Text + " 00:00:00.000");


             // SqlCommand myCommand = new SqlCommand("select* from  Operation,Lots,Data where Operation.Num=Lots.Num and Data.Date textBox1 Operation.Start_Date and Operation.End_Date and Data.Date_Now textBox1 "+Convert.ToDateTime(startpurge.Text)+" and "+Convert.ToDateTime(Endpurge.Text), Program.Connexion);
                // SqlCommand myCommand = new SqlCommand("select* from  Operation,Lots,Data where Operation.Num=Lots.Num and Data.Date textBox1 Operation.Start_Date and Operation.End_Date", Program.connexion);
                //  DELETE FROM OpEnCours where Label='" + EtuveASupprimer + "'", Program.connexion);

              /*
                SqlCommand myCommand3 = new SqlCommand("DELETE from  Lots where  Lots.Num in(select Lots.Num from  Operation,Lots where Operation.Num=Lots.Num and Operation.Start_Date between '" + D1 + "' and '" + D2 + "') ", Program.connexion);
                myCommand3.ExecuteReader();
               Program.connexion.Close();*/

                              
               Program.connexion.Open();
               SqlCommand myCommand = new SqlCommand("DELETE from  Live_Operation where End_Date between '" + D1 + "' and '" + D2 + "'", Program.connexion);
                myCommand.ExecuteReader();
                Program.connexion.Close();
                
               Program.connexion.Open();
             
          /* SqlCommand commande = new SqlCommand("DELETE  from  Data where Date_Now between '" + D1 + "' and '" + D2 + "'", Program.connexion);
           commande.ExecuteNonQuery(); */


                richTextBox.Text = "\n Archives between " + monthstart.Text + "/" + daystart.Text + "/" + yearstart.Text + " and " + monthend.Text + "/" + dayend.Text + "/" + yearend.Text + " are deleted succefully...";
            }
            catch (Exception) { richTextBox.Text = "\nNo data... "; }
            Program.connexion.Close();
        }




merci d'avance

3 réponses

cs_Megafan Messages postés 389 Date d'inscription dimanche 7 avril 2002 Statut Membre Dernière intervention 23 septembre 2016 2
14 avril 2011 à 19:50
myCommand.ExecuteReader(); ?

plutôt

myCommand.ExecuteNonQuery();


Megafan

Développeur de http://www.o10c.eu (Lien)


La nouvelle référence en matière de jeu de stratégie spatiale.
0
kaoutarac Messages postés 26 Date d'inscription mercredi 15 décembre 2010 Statut Membre Dernière intervention 6 septembre 2012
15 avril 2011 à 11:18
Bonjour
j ai déjà essai avec myCommand.ExecuteNonQuery();
Mais j ai toujours des champs comprises entre l intervalle sélectionné qui ne sont pas supprimées
merci
0
cs_Megafan Messages postés 389 Date d'inscription dimanche 7 avril 2002 Statut Membre Dernière intervention 23 septembre 2016 2
17 avril 2011 à 09:20
Alors peut être aussi au niveau de vos formats de date

Personellement j'utiilise tout le temps la même formul lorsque je traite une date pour mettre en base.

Dim UneDate as date
Dim SqlUneDate As String = "CONVERT(DATETIME,'" + Format(UneDate, "yyy-MM-dd HH:mm:ss") + "',102)"

Vous utilisez 'SqlUneDate' Dans la chaine de requête

A tout hasard :
Avez vous essayé la requête dans le management studio ?


Megafan

Développeur de http://www.o10c.eu (Lien)


La nouvelle référence en matière de jeu de stratégie spatiale.
0
Rejoignez-nous