comment rendre une verification de connectionbeaucoup plus rapide ?

cs_6miK Messages postés 61 Date d'inscription mardi 10 avril 2007 Statut Membre Dernière intervention 5 avril 2011 - 25 avril 2007 à 14:45
cs_coq Messages postés 6349 Date d'inscription samedi 1 juin 2002 Statut Membre Dernière intervention 2 août 2014 - 1 mai 2007 à 01:16
Bonjour,
j'aimerais savoir
comment faire une vérification beaucoups plus rapide, car ceci mais
tout de même un certain temps lorsqu'il sagit de vérifier que l'on a à
faire à un fournisseur.
Le code ci dessous n'est pas compliqué du tout mais très long à l'exécution.
Si qu'elqu'un pouvait m'aider.
Merci d'avance.

OdbcConnection con;

   void BoutonValider(object sender, EventArgs e)
     {
         OdbcCommand command;
         string sql;
         con = new OdbcConnection(ConfigurationSettings.AppSettings["connexion"]);
         con.Open();

         Label1.Text="";
         Label2.Text="";
         Label3.Text="";
         Label4.Text="";
         if(TextBox1.Text.Length 0 || TextBox2.Text.Length 0)
         {
           if (TextBox1.Text.Length == 0)
           {
              Label2.Text="* Veuillez saisir un login";
           }

           if (TextBox2.Text.Length == 0)
           {
               Label3.Text="* Veuillez saisir un mot de pass";
           }
         }

         else
         {
          
sql "SELECT nomU, mdpU, prenomU FROM `utilisateur` WHERE nomU '" +
TextBox1.Text + "' AND mdpU = '" + TextBox2.Text + "'";
           command = new OdbcCommand(sql, con);
           command.ExecuteNonQuery();

           if(command.ExecuteNonQuery() > 0)
           {

               DataSet data = new DataSet();
               OdbcDataAdapter adapter = new OdbcDataAdapter(sql, con);
               adapter.Fill(data);
               DataTable maTable = data.Tables[0];

               foreach (DataRow row in maTable.Rows)
               {
                   string r0 = (string)row[0];
                   string r1 = (string)row[1];
                   string r2 = (string)row[2];
                   if(TextBox1.Text.ToUpper() r0.ToUpper() && TextBox2.Text.ToUpper() r1.ToUpper())
                   {

                       Label1.Text += "Bienvenu " + r2 + " " + r0 + " !";

                   }
               }
           }
           else
           {
           sql "SELECT nomC, mdpC FROM `client` WHERE nomC '" + TextBox1.Text + "' AND mdpC = '" + TextBox2.Text + "'";
           command = new OdbcCommand(sql, con);
           command.ExecuteNonQuery();

           if(command.ExecuteNonQuery() > 0)
           {

               DataSet data = new DataSet();
               OdbcDataAdapter adapter = new OdbcDataAdapter(sql, con);
               adapter.Fill(data);
               DataTable maTable = data.Tables[0];

               foreach (DataRow row in maTable.Rows)
               {
                   string r0 = (string)row[0];
                   string r1 = (string)row[1];
                   if(TextBox1.Text.ToUpper() r0.ToUpper() && TextBox2.Text.ToUpper() r1.ToUpper())
                   {
                       Label1.Text += "Bienvenu client : " + r0 + " !";
                   }
               }
           }
           else
           {           sql "SELECT nomF, mdpF FROM `fournisseur` WHERE nomF '" + TextBox1.Text + "' AND mdpF = '" + TextBox2.Text + "'";
           command = new OdbcCommand(sql, con);
           command.ExecuteNonQuery();

           if(command.ExecuteNonQuery() > 0)
           {
               DataSet data = new DataSet();
               OdbcDataAdapter adapter = new OdbcDataAdapter(sql, con);
               adapter.Fill(data);
               DataTable maTable = data.Tables[0];

               foreach (DataRow row in maTable.Rows)
               {
                   string r0 = (string)row[0];
                   string r1 = (string)row[1];
                   if(TextBox1.Text.ToUpper() r0.ToUpper() && TextBox2.Text.ToUpper() r1.ToUpper())
                   {
                      Label1.Text += "Bienvenu fournisseur : " + r0 + " !";
                   }
               }
           }
           else
           {
                Label4.Text += "erreur : Mauvais login ou mot de pass";
           }
         }
       }
        con.Close();
  }

}

1 réponse

cs_coq Messages postés 6349 Date d'inscription samedi 1 juin 2002 Statut Membre Dernière intervention 2 août 2014 101
1 mai 2007 à 01:16
Salut,

Déjà, pas de concaténation de chaines pour les requêtes SQL, mais utiliser des requêtes paramétrées.

Ensuite tu utilises des concaténations de chaines un peu partout dans tes boucles, ce qui peut avoir un impact extremement négatif sur les perfs : les String sont immuables, toute opération sur la chaine entraine la création d'une nouvelle instance de String, suivant le volume de données traitées ça peut se faire très lourdement sentir => StringBuilder

Au lieu de faire des ToUpper partout, faire des comparaisons insensibles à la casse : voir la méthode String.Compare

/*
coq
MVP Visual C#
CoqBlog
*/
0
Rejoignez-nous