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
|
void getOnlineData()
{
string server = "host2.hostonik.com";
string port = "2083";
string database = "fack_test";
string username = "username";
string password = "passwrd";
string mysql_connect = String.Format("SERVER={0};PORT={1};DATABASE={2};UID={3};PWD={4}", server, port, database, username, password);
using (MySqlConnection cnx = new MySqlConnection(mysql_connect))
{
try
{
cnx.Open();
string query = "select * from annonce";
using (MySqlCommand cmd = new MySqlCommand(query, cnx))
{
MySqlDataReader r = cmd.ExecuteReader();
dataGridView1.Rows.Clear();
while (r.Read())
{
dataGridView1.Rows.Add(r.GetInt32(0), r.GetString(1), r.GetString(3), r.GetString(4), r.GetDouble(5), r.GetDouble(6), r.GetString(8), r.GetInt32(7));
}
}
cnx.Close();
}
catch (Exception ex)
{
MessageBox.Show("erreur MySQL :" + ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
} |
Partager