Пример #1
0
 /// <summary>
 /// méthode  utilisée principalement pour des opérations de type UPDATE, INSERT, DELETE
 /// </summary>
 /// <param name="sqlCommand">Chaine SQL à exécuter</param>
 /// <returns>Nombre d'enregistrements traités</returns>
 public int ExecuteNonQuery(string sqlCommand)
 {
     try
     {
         int returnValue;
         OpenDBCnx();                                        // on ouvre une connexion a la base de donné
         OleDbCommand Command = Connexion.CreateCommand();   // on crée une nouvelle commande
         CurrentTransaction  = Connexion.BeginTransaction(); //
         Command.Connection  = Connexion;                    // on assoucie une commande a une connexion
         Command.Transaction = CurrentTransaction;
         Command.CommandType = CommandType.Text;             // on defenit le type de la commande a executer
         Command.CommandText = sqlCommand;                   //chaine sql a executer
         returnValue         = Command.ExecuteNonQuery();    // executer la requette
         CurrentTransaction.Commit();
         return(returnValue);                                //nombre d'enregistrements traités
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);// on genere un message d'echec en cas d'erreur
     }
     finally
     {
         CloseDbCnx();// on ferme la connection
     }
 }