jeudi 22 juin 2017

Pull SQL value then run If/Else statement

I want to take the value of agronomy either yes/no... if yes it opens another form if no it pops up a message box... just can't seem to wrap my head around how to pull that stored value from the SQL command. Any help would be great I am sure it is something super simple...

SqlConnection cn = new SqlConnection(@"Data Source=*****;Initial Catalog=agSale;Integrated Security=True");
        SqlCommand cmd = new SqlCommand("SELECT agronomy from logins where userName = @userName", cn);
        cmd.Parameters.AddWithValue("userName", nameLabel.Text);
        cn.Open();
        SqlDataReader reader = cmd.ExecuteReader();


        if (agronomy == "yes") 
             new agronomy().Show();
        else
            MessageBox.Show("You can't access this part of the program.  For questions call 867-5309.");


        cn.Close();

Aucun commentaire:

Enregistrer un commentaire