mercredi 30 octobre 2019

Cannot implicitly convert type 'int' to 'bool' with if function

Hello !

I'm trying to link a Checkbox to SQL, displaying a bool value (checked = 1, unchecked = 0).
I have a misunderstanding about the Boolean demonstrated in my code.
When i build it, i get this error :

CS0029 C# Cannot implicitly convert type 'int' to 'bool'

Here's my code :

private void IsHere_Loaded(object sender, RoutedEventArgs e) // My CheckBox
        {
            object visiteur = CbSelectedName.SelectedItem; 

            SqlConnection con = new SqlConnection("MyConnString");

            SqlCommand status = new SqlCommand("SELECT column FROM table WHERE column_name = '" + visiteur + "'", con);

            con.Open();

            var result = status.ExecuteNonQuery();

            if (result = 1) // <-- CS0029 Error here

                isHere.IsChecked = true;

            else
                    isHere.IsChecked = false;
        }

Why is the if() function not correct ? Did I forget something ?
Thank you in advance,
Zancrew.




Aucun commentaire:

Enregistrer un commentaire