I need the name of the package to appear in the history table but the id_package is appearing

Asked

Viewed 40 times

1

public List<HistoricoViagem> ObterTodosParaJSON(string start, string length)
    {
        List<HistoricoViagem> historicoViagens = new List<HistoricoViagem>();
        SqlCommand command = new Conexao().ObterConexao();
        command.CommandText = @"SELECT hv.id, p.id, hv.id_pacote, hv.data_, p.nome FROM historico_de_viagens hv
        INNER JOIN pacotes p ON (p.id_pacote = hv.id_pacote)";
        DataTable tabela = new DataTable();
        tabela.Load(command.ExecuteReader());
        foreach (DataRow linha in tabela.Rows)
        {
            HistoricoViagem historicoViagem = new HistoricoViagem()
            {
                Id = Convert.ToInt32(linha[0].ToString()),
                IdPacote = Convert.ToInt32(linha[2].ToString()),
                Data = Convert.ToDateTime(linha[3].ToString()),
                Pacote = new Pacote()
                {
                    Id = Convert.ToInt32(linha[1].ToString()),
                    Nome = linha[4].ToString()
                }


            };
            historicoViagens.Add(historicoViagem);
        }
        return historicoViagens;
    }

This is the code where I need to bring the package name

$(function () {
 $('#guia-tabela').DataTable({
    "processing": true,
    "serverSide": true,
    "ajax": "/Guia/ObterTodosPorJSON",
    "columns": [
        { "data": "Id" },
        { "data": "Nome" },
        { "data": "Sobrenome" },            
        { "data": "Cpf" },
        { "data": "Rank" }
    ]
 });
});

that’s the table

  • And I need to win in mega sena hehehehe. You really need those objects as described in columns? And if you need to, why are you populating a completely different one? What exactly is your question?

  • use line["nomedacoluna"]

1 answer

0

Puts Alias in your select.

SELECT hv.id as "id do hv", p.id as "id do p", hv.id_pacote as "id do pacote",
       hv.data as "data", p.nome as "nome" 
FROM historico_de_viagens hv INNER JOIN pacotes p ON (p.id_pacote = hv.id_pacote)
  • 1

    Thank you ! everything worked out

  • You’re welcome! Glad to have helped.

Browser other questions tagged

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