我想要的是当我单击连接按钮时,打开与 MySQL 的连接,我可以使用连接的数据库并且所有文本框都被禁用,如果我单击断开连接,我想关闭连接,用户将无法使用连接数据库,并且所有文本框都已启用。
任何人都可以帮助我进行此验证!
这是我在连接按钮中的代码:
连接是 MySQLConnection 全局变量
connection = new MySqlConnection(strConnection);
if(connection.State == ConnectionState.Closed)
{
connection.Open();
}
这是我在断开按钮中的代码:
if (connection.State != ConnectionState.Closed)
{
connection.Close();
}
This does not work because when the disconnect button is selected the connection variable becomes null, which I do not want. 我想保持连接变量的状态。