Error 1 No overload for method 'MethodHerdado' takes 1 arguments

-2

Error:

Error 1 No overload for method 'MétodoHerdado ' 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;
    }
    
asked by anonymous 10.08.2018 / 15:45

2 answers

1

On this line

 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 above, it might be this.tabela.Nome and this.tabela.Campo the strings that you have to pass.

Check the signature, see if you have no overload that only receives 1. Or to use it, pass both strings.

    
10.08.2018 / 15:52
5

First of all, I suggest you look for a book, a course, because you are doing a very complex code without understanding what is happening in it, it does not work, you are wrong and you are making mistakes that you are not aware of because you do not understand. The code is full of errors, but it will work, until one day it will fail and neither will know why. Programming is much more complicated than you think and it is missing out on basic things.

Your specific error that luckily made you wrong and prohibited you from doing wrong has to do with something called overload of methods . Methods can have more than one signature , but in this case the error message is generic, nor does it need to have one more , the fact that only 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 of which get a string , one seems to be the name of the table, and another the primary key (bad variable names). When you make the call you are only passing this.tabela , that is, only one argument. Then there is no way to solve it. You need to pass another 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 do not know because it does not have in the code something that we know to be the field.

Anyway, I would not do what you're trying to do, especially without understanding the consequences of it. It already seems to be a pretty gambiarra in the database, but I do not have all the data to state. The very idea of having something that catches the next code is conceptually wrong and will cause problems in a competitive environment. You'll be desperate when it starts giving errors that seem random and will not get help solving it.

Understand Why can you define two or more methods with the same name in the same class in C #? .

    
10.08.2018 / 15:56