DataGridView displaying incomplete id

2

The grid displays only the first character of the "ID"

For example: if the ID is 16 it displays 1; If it is 20 it displays 2;

But from 1 to 9 displays correctly ...

Codethatselectsdata...

privatevoidlixeiraDialog_Load(objectsender,EventArgse){//carregadobancotodososregistrosexcluidos(status=0)MySqlCommandsql=this.conexaoBanco.criaComandoSQL("sp_select_lixeira");
            sql.Parameters.Add(new MySqlParameter("nome_tabela", this.tabela));
            sql.Parameters.Add(new MySqlParameter("id_tabela", this.pk));
            sql.Parameters.Add(new MySqlParameter("campo_tabela", this.campo));
            //preenche o dataset
            MySqlDataAdapter mda = new MySqlDataAdapter(sql);
            mda.Fill(this.dadosTabela);

            //carrega o datagrid com os dados do dataset
            this.gridRegistrosDeletados.DataSource = this.dadosTabela.Tables[0];
            this.gridRegistrosDeletados.Columns[0].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
        }

Procedure:

CREATE DEFINER='root'@'localhost' PROCEDURE 'sp_select_lixeira'(
    IN nome_tabela VARCHAR(255),
    IN id_tabela VARCHAR(10),
    IN campo_tabela VARCHAR(255)
)
    DETERMINISTIC
BEGIN
DECLARE maxDigitos varchar(11);
DECLARE comandoSQL VARCHAR(255);

-- pega o tamanho do campo codigo e atribui o valor na variavel maxDigitos --

SET @comandoSQL = CONCAT("SELECT (" ,id_tabela, ") FROM ", nome_tabela," LIMIT 1 INTO @maxDigitos");
PREPARE consulta FROM @comandoSQL;
EXECUTE consulta;
deallocate prepare consulta;

SET @comandoSQL = CONCAT("SELECT LPAD(",id_tabela,", ",@maxDigitos,", 0) AS ",id_tabela,", ", campo_tabela," AS descricao FROM ", nome_tabela," WHERE status = 0");

PREPARE consulta FROM @comandoSQL;
EXECUTE consulta;
deallocate prepare consulta;
END
    
asked by anonymous 30.08.2018 / 22:10

1 answer

2
CREATE DEFINER='root
'@'localhost' PROCEDURE 'sp_select_lixeira'(
    IN nome_tabela VARCHAR(255),
    IN id_tabela VARCHAR(10),
    IN campo_tabela VARCHAR(255)
)
    DETERMINISTIC
BEGIN
    DECLARE maxDigitos varchar(11);
    DECLARE comandoSQL VARCHAR(255);

    -- pega o tamanho do campo codigo e atribui o valor na variavel maxDigitos --

    SET @comandoSQL = CONCAT("SELECT (" ,id_tabela, ") FROM ", nome_tabela," LIMIT 1 INTO @maxDigitos");
    PREPARE consulta FROM @comandoSQL;
    EXECUTE consulta;
    deallocate prepare consulta;

    SET @comandoSQL = CONCAT("SELECT (",id_tabela," ) AS ",id_tabela,", ", campo_tabela," AS descricao FROM ", nome_tabela," WHERE status = 0");

    PREPARE consulta FROM @comandoSQL;
    EXECUTE consulta;
    deallocate prepare consulta;
END

It was a mistake in the procedure ... I did it the wrong way ... Lack of coffee maybe

    
30.08.2018 / 22:45