error ,the commandtext property has not been properly initialized

Viewed 28
private void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                string username = txtUsername.Text;
                var password = txtPassword.Text;

                connection.Open();
                command=new MySqlCommand(query, connection);
                query = "select * from user where username=@username and password=@password";
                command.Parameters.AddWithValue("@username", username);
                command.Parameters.AddWithValue("@password", password);
                int i = command.ExecuteNonQuery();

                if (i != 0)
                {
                    MessageBox.Show("Login success");
                    Stock stock = new Stock();
                    stock.Show();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show("Login Unsuccess");
                }
                connection.Close();


            }
            catch (Exception exception)
            {

                MessageBox.Show(exception.Message);

            }
            
        }
0 Answers
Related