I would like to know how to enable button based on mysql value.
I have database called database. Inside database table users and row uploader (varchar(45)) text in row is "True".
Here is my code ... but it doesn't work. Any solution would be great.
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);
}
usingstatement. This would handle the closing of the connection, even if there is an exception.usingstatement for your connections.if (uploader == "True")it's possible this case-sensitive comparison is failing, depending on what's in your database. You really should store boolean values if it's a boolean field.