Advertisement
Guest User

Untitled

a guest
Feb 25th, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.21 KB | None | 0 0
  1.             bool Recherche(string Champ)
  2.             {
  3.                 MySqlConnection maConnexion = new MySqlConnection("Server=192.168.1.11;Database=bdlycee;Uid=jeremy;Pwd=iris2;");
  4.                 string maRequeteRecherche;
  5.                 MySqlCommand maCommandeRecherche;
  6.                 maRequeteRecherche = "SELECT @Champ FROM tbladmin WHERE fldIdentifiant = @Id";
  7.                 maCommandeRecherche = new MySqlCommand(maRequeteRecherche, maConnexion);
  8.                 maCommandeRecherche.Parameters.Add(new MySqlParameter("@Id", MySqlDbType.String, 11));
  9.                 try { maCommandeRecherche.Parameters["@Id"].Value = Convert.ToInt32(mainForm.textBoxResultatAdm.Text); }
  10.                 catch { mainForm.labelErreurCodeAdm.Text = "Code barre ou QR code invalide"; return false;}
  11.                 maCommandeRecherche.Parameters.Add(new MySqlParameter("@Champ", MySqlDbType.String, 14));
  12.                 try { maCommandeRecherche.Parameters["@Champ"].Value = Champ; }
  13.                 catch { mainForm.labelErreurCodeAdm.Text = "Erreur au niveau du champ"; return false;}
  14.                 try
  15.                 {
  16.                     maCommandeRecherche.Connection.Open();
  17.                     if (maCommandeRecherche.ExecuteScalar() == null)
  18.                     {    
  19.                         maCommandeRecherche.Connection.Close();
  20.                         return false;
  21.                     }
  22.                     else
  23.                     {
  24.                         if (Admin == true)
  25.                         {
  26.                             maCommandeRecherche.ExecuteNonQuery();
  27.                             MdpBD = Convert.ToString(maCommandeRecherche.ExecuteScalar());
  28.                             if (MdpBD == MdpChiffre)
  29.                                 return true;
  30.                             else
  31.                                 return false;
  32.                         }
  33.                         else
  34.                         {
  35.                             maCommandeRecherche.Connection.Close();
  36.                             return true;
  37.                         }
  38.                     }
  39.                 }
  40.                 catch { MessageBox.Show("Erreur au niveau de la requête de recherche"); return false; }
  41.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement