I want to make visible a button, but only when a string exists. This is the way I thought, but I’m not seeing any change to my UI. Furthermore, the loop doesn’t exit, despite only returning a single result.
using (MySqlConnection con = new MySqlConnection(ConnStr))
{
con.Open();
string sqlCON = "SELECT CV_EXIST FROM DATA_NEURON.DM_CV WHERE DWH_CUSTOMER_KEY = '123321'";
MySqlCommand cmd = new MySqlCommand(sqlCON con);
using (MySqlDataReader rdr = cmd.ExecuteReader())
{
while (rdr.Read())
{
var check = rdr.GetString(0);
if (check == "YES")
{
button_cv.Visible = true;
}
else
{
button_cv.Visible = false;
}
}
}
}
Thank you and sorry for my english.
2
Answers
Please note, that in your current implementation
button_cv
doesn’t change its state when cursor is empty andwhile
loop is not entered; anotherpossible issues are (trailing) spaces (
"YES "
) and case ("yes"
,"Yes"
etc.). If it is "doesn’t work" then I suggest something like this:Here I’ve assumed that empty cursor means
NO
; if it isYES
then all you need is to change a single line by adding?? "YES"
:this code has syntax error :
best way is write a method for recognize button visibility and use its :