No Overload for Matches delegate error on a C#

Asked

Viewed 306 times

-2

I am programming a button that checks if the login is existing and advances to another screen but appears the following error:

"no Overload for 'btnEntrar_Click' Matches delegate 'Eventhandler'"

private void btnEntrar_Click(object sender, EventArgs e, String login, String senha)
{
    Cadastrar cad = new Cadastrar();
    cad.Acessar(txtLogin.Text, txtSenha.Text);
    if (cad.tem)
    {
        string nomeusu;
        MessageBox.Show("Logado com sucesso","Entrando",MessageBoxButtons.OK,MessageBoxIcon.Information);
        pnlCadMat.Visible = true;

        cmd.CommandText = "SELECT nome_estudantes FROM Estudantes WHERE @login = email_estudantes AND @senha = senha_estudantes";
        nomeusuario = cmd.ExecuteReader();

        nomeusu = Convert.ToString(nomeusuario);

        cadh.lblNomeUsuario.Text = nomeusu;
    }
    else
    {
        MessageBox.Show("LOGIN NAO ENCONTRADO", "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }
}

2 answers

0

The click event can only have 2 parameters. A object that represents the element that triggered the event and a EventArgs which are different arguments for events (for example: an event in a Datagridview may contain the row and column that triggered the event).

Therefore, the signing of the event should be

private void btnEntrar_Click(object sender, EventArgs e)

0

You can have two parameters in private void btnEntrar_Click that are the arguments (object sender, EventArgs e), you can try to pass your parameters inside an invisible text box for example, put the values there and use for your function

    private void btnEntrar_Click(object sender, EventArgs e)
    {
        string login = SuaTextBoxLogin.text;
        string senha = SuaTextBoxSenha.senha;

        Cadastrar cad = new Cadastrar();
        cad.Acessar(login, senha);
        if (cad.tem)
    {
        string nomeusu;
        MessageBox.Show("Logado com 
        sucesso","Entrando",MessageBoxButtons.OK,MessageBoxIcon.Information);
        pnlCadMat.Visible = true;

        cmd.CommandText = "SELECT nome_estudantes FROM Estudantes WHERE @login = 
        email_estudantes AND @senha = senha_estudantes";
        nomeusuario = cmd.ExecuteReader();

        nomeusu = Convert.ToString(nomeusuario);

        cadh.lblNomeUsuario.Text = nomeusu;
    }
    else{
        MessageBox.Show("LOGIN NAO ENCONTRADO", "ERRO", MessageBoxButtons.OK, 
        MessageBoxIcon.Information);
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.