Error 1 No Overload for method 'Inherited method' takes 1 Arguments

Asked

Viewed 441 times

-2

Error 1 No Overload for method 'Inherited method' takes 1 Arguments

Code:

    public void restauraRegistro(DataGridViewRow linha)
    {
        
        try
        {
            string codigo = String.Empty;

            
            //verifica se e para recuperar com outro codigo
            if (this.checkRecuperaOutroCodigo.Checked)
                codigo = this.conexaoBanco.proximoCodigo(this.tabela).ToString(); //Limha do erro

                
            MySqlCommand sql = this.conexaoBanco.criaComandoSQL ("sp_restaura_registro");
            sql.Parameters.Add(new MySqlParameter("sp_codigo", linha.Cells["codigo"].Value));
            sql.Parameters.Add(new MySqlParameter("sp_tabela", this.tabela));
            sql.Parameters.Add(new MySqlParameter("sp_codigo_novo", codigo));

            this.conexaoBanco.executaQuery(sql);
            //remove do datagrid a linha
            this.gridRegistrosDeletados.Rows.RemoveAt(linha.Index);
            this.removeuRegistro = true;
        }

        catch (MySqlException erro)
        {
            this.removeuRegistro = false;
            MessageBox.Show("Ocorreu um erro ao restaurar o registro.\nErro: " + erro.Message, "Atenção!", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }

Method called

/// <summary>
    /// Retorna o próximo codigo da tabela
    /// </summary>
    /// <param name="tb">Nome da Tabela</param>
    /// <param name="pk">Nome do Campo</param>
    /// <returns>inteiro proximo codigo</returns>
    public int proximoCodigo(string tb, string pk)
    {
        int resultado = 0;
        MySqlCommand cmd = new MySqlCommand("sp_proximo_codigo", objConnection);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add(new MySqlParameter("_data_base", "folha"));
        cmd.Parameters.Add(new MySqlParameter("_tabela", tb));
        cmd.Parameters.Add(new MySqlParameter("_campo", pk));

        if (!this.OpenConnection())
            return 0;

        MySqlDataReader dataReader = cmd.ExecuteReader();
        while (dataReader.Read())
            resultado = int.Parse(dataReader["retorno"].ToString());

        dataReader.Close();
        this.CloseConnection();

        return resultado;
    }
  • 1

    Check the method signature proximoCodigo, you certainly do not receive a parameter (you can receive more or less).

  • I’m making this mistake, Aug can help me :(

  • ERROR: Error 1 No Overload for method 'Inherited method' takes 1 Arguments

  • 1

    Within the method proximoCodigo is evoking that method? Check the signature of both methods.

  • Damn, I didn’t even see that method proximoCodigo was in your code.

2 answers

5

First of all I suggest looking for a book, a course, because you’re making a very complex code without understanding what’s going on in it, it doesn’t work, you’re mistaken and you’re making mistakes that aren’t noticeable because you don’t understand. The code is full of errors, but it will work, until one day it will fail and you won’t even know why. Programming is much more complicated than you think and you’re missing basic things.

Your specific mistake that luckily made an explicit mistake and forbade you from doing wrong has to do with something called Overload of methods. Methods can have more than one signing, but in this case the error message is generic, nor need to have one more, the fact that only have 1 is enough to give the error when the call does not match the method definition.

Note that you wrote a method with 2 parameters, both receiving one string, one seems to be the table name and the other the primary key (bad variable names). When you make the call you are passing only this.tabela, That is, only one argument. So there is no way to solve it. You need to pass another string string string`to call the correct method. The compiler gets confused thinking that it should have a method with only 1 parameter. The exact solution we don’t know because there’s something in the code that we know is the field.

Anyway, I wouldn’t do what you’re trying to do, especially without understanding all the consequences of it. It already looks like a nice hack in the database, but I don’t have all the data to back it up. The very idea of having something that takes the next code is conceptually wrong and will cause problems in a competitive environment. You’ll be desperate when this starts to make mistakes that seem random and won’t get help to solve it.

Understand Why it is possible to define two or more methods with the same name in the same class in C#?.

  • So buddy, it was more of a lack of attention from me, I accidentally blacked out

  • public int proximoCodigo(string tb, string pk = "id_inss")

  • Which was pre-defined, but anyway thank you very much !!!

  • The system has a "data recycle bin", and it is possible to recover the data using another code... Only by this the next code.

  • I understand that it is not the correct way of functioning, but it is what I was asked basically

  • @vinibsc I’m sorry, but I doubt that anyone asked to do everything wrong, but of course you do as you wish.

Show 1 more comment

1


Along those lines

 codigo = this.conexaoBanco.proximoCodigo(this.tabela)

You are calling the method by passing 1 parameter (this.tabela)

And as the error says, your method expects two strings

 public int proximoCodigo(string tb, string pk)

By the Summary up there, it might be this.tabela.Nome and this.tabela.Campo the strings you have to pass.

Check the signature, see if there is no Overload that only gets 1. Or to use this one, pass the two strings.

  • Solved, thank you !!!

Browser other questions tagged

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