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
| private void button1_Click(object sender, EventArgs e)
{
bool result = false;
string ConString = "Server=localhost;Database=db_com;uid=root;Pwd=";
MySqlConnection ConnectionDB = new MySqlConnection(ConString);
try
{
ConnectionDB.Open();
result = true;
ConnectionDB.Close();
}
catch (Exception ex)
{
result = false;
}
if (result)
{
MessageBox.Show("La base de données existe");
}
else
{
MessageBox.Show("La base de données n'existe pas");
try
{
MySqlCommand Cmd = new MySqlCommand("CREATE DATABASE db_com");
Cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show("La base de données db_com n'a pas été créée!");
}
}
} |
Partager