我想知道如何启用基于mysql值的按钮。c#启用基于mysql值的按钮
我有数据库调用数据库。内部数据库表用户和行上传器(varchar(45))行中的文本是“True”。
这是我的代码...但它不起作用。任何解决方案都会很棒。
try
{
string myConnection = "datasource=localhost;port=3306;username=root;password=pass";
MySqlConnection myConn = new MySqlConnection(myConnection);
MySqlCommand SelectCommand = new MySqlCommand("select uploader from database.users where username='" + c.username_txt.Text + "' ;", myConn);
MySqlDataReader myReader;
myConn.Open();
myReader = SelectCommand.ExecuteReader();
while (myReader.Read())
{
Console.WriteLine(myReader.GetString(myReader.GetOrdinal("uploader")));
}
string uploader = Console.ReadLine();
if (uploader == "True")
{
uploadToolStripMenuItem.Enabled = true;
}
else
myConn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
你这是什么意味着_it不工作?任何异常或错误信息? –
你应该把你的连接放在'using'语句中。这将处理关闭连接,即使有异常。 –
请使用[参数化查询](http://www.codinghorror.com/blog/2005/04/give-me-parameterized-sql-or-give-me-death.html)。也可以使用'using'语句进行连接。 –