1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
{
Log("Début test MySql.Data.MySqlClient");
List<A> listA = new List<A>();
A tempA;
int nb_total = 0;
string mySelectQuery, mySelectQuery2;
// Connection à la base
MySqlConnection myConnection = new MySqlConnection(myConnectionString);
myConnection.Open();
// Recherche de la liste des As
mySelectQuery = "SELECT A_ref, A_code FROM A WHERE A_etat>=1";
MySqlCommand myCommand_select = new MySqlCommand(mySelectQuery, myConnection);
MySqlDataReader myReader;
myReader = myCommand_select.ExecuteReader();
// Initialisation de la liste
while (myReader.Read())
{
tempA = new A();
tempA.A_ref = myReader.GetString("A_ref");
tempA.A_code = myReader.GetString("A_code");
listA.Add(tempA);
nb_total++;
}
myReader.Close();
myCommand_select.Connection.Close();
// Initialisation de la barre de progression
pb_maj.Maximum = nb_total;
pb_maj.Value = 0;
MySqlCommand myCommand_update;
myConnection.Open();
// Parcours de la liste
for (int indice = 0; indice < listA.Count; indice++)
{
// Mise à jour du code
mySelectQuery2 = "UPDATE A SET A_code='" + calculCode(listA[indice].A_code) + "', A_datemodif=Now() WHERE A_ref='" + listA[indice].A_ref + "'";
myCommand_update = new MySqlCommand(mySelectQuery2, myConnection);
myCommand_update.ExecuteNonQuery();
pb_maj.Value++;
}
//myCommand_update.Connection.Close();
//Fermeture de la base
myConnection.Close();
Log("Fin test MySql.Data.MySqlClient");
MessageBox.Show(this, "Fin");
} |