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
|
public void Program()
{
MySQLConnection conn = new MySQLConnection( new MySQLConnectionString("le_nom_du_serveur","le_nom_de_la_base_de_données","le_login","le_password").AsString );
ResultTextBox.Text = "Connexion à la base de données\n";
conn.Open();
// Méthode 1 MysqlCommand
ResultTextBox.Text += "Constitution de la requète Méthode 1 : MySQLCommand\n";
MySQLCommand cmd = new MySQLCommand("select TITRE,ISBN, DATEPAR from livre where EDITEUR = 'Dunod' and DATEPAR > '200301' limit 0,10",conn);
ResultTextBox.Text += "Execution de la requète\n";
MySQLDataReader reader = cmd.ExecuteReaderEx();
ResultTextBox.Text += "Lecture des résultats\n";
while(reader.Read())
{
ResultTextBox.Text += "ISBN :"+reader.GetString(1)+ " , Parution :"+reader.GetString(2)+" , Titre:"+reader.GetString(0)+"\n";
}
reader.Close();
cmd.Dispose();
// Méthode 2 MySQLSelectCommand
ResultTextBox.Text += "Constitution de la requète Méthode 2 : MySQLSelectCommand\n";
DataTable dt = new MySQLSelectCommand(conn, new string[] {"TITRE","ISBN","DATEPAR"}, new string[] {"livre"}, new object[,] {{"EDITEUR","=","Dunod"},{"DATEPAR",">","200301"}}, null, null, true, 0, 10, false).Table;
foreach(DataRow row in dt.Rows)
{
ResultTextBox.Text += "ISBN:"+row["ISBN"].ToString()+" ,Parution :"+row["DATEPAR"].ToString()+" , TITRE:"+row["TITRE"].ToString()+ "\n";
}
ResultTextBox.Text += "Fermeture de la Connexion\n";
conn.Close();
ResultTextBox.Text += "Process de lecture terminé\n";
} |
Partager