AspNet Core 2.1 - ADO.NET

AspNet Core 2.1 - ADO.NET

marcelovbamarcelovba Posts: 2Questions: 0Answers: 0
edited June 2019 in Free community support

Hello, I have a project with ASP NET Core 2.1 with ADO.NET and I could not display the data in the datatable.
Can you tell me where I'm going wrong?

Models:

public class ColaboradorDAL
    {
        string connectionString = ConnectionString.CName;

        //To View all employees details      
               
        public IEnumerable<Colaborador> ListaTodosColaboradores()
        {
            List<Colaborador> lstcolaborador = new List<Colaborador>();

            using (SqlConnection con = new SqlConnection(connectionString))
            {
                SqlCommand cmd = new SqlCommand("uSP_ListaColaboradores", con)
                {
                    CommandType = CommandType.StoredProcedure
                };

                con.Open();
                SqlDataReader rdr = cmd.ExecuteReader();

                while (rdr.Read())
                {
                    Colaborador colaborador = new Colaborador
                    {
                        ID = Convert.ToInt32(rdr["ID"]),
                        NomeFuncionario = rdr["NomeFuncionario"].ToString(),
                        Endereco = rdr["Endereco"].ToString(),
                        Funcao = rdr["Funcao"].ToString(),
                        Email = rdr["Email"].ToString(),
                        Sexo = rdr["Sexo"].ToString()
                    };


                    lstcolaborador.Add(colaborador);
                }
                con.Close();
            }
            return lstcolaborador;
        }

Controller:

public ActionResult GetList()
        {
            var colabList = colaboradorDAL.ListaTodosColaboradores().ToList<Colaborador>();
            return Json(new { data = colabList });
        }

View Index:

 $(document).ready(function () {

            $("#employeeTable").DataTable(
                {
                    "ajax": {
                        "url": "/Colaborador/GetList",
                        "type": "GET",
                        "datatype": "json"
                    },
                    
                    "columns": [
                        { "data": "ID" },
                        { "data": "NomeFuncionario" },
                        { "data": "Endereco" },
                        { "data": "Funcao" },
                        { "data": "Email" },
                        { "data": "Sexo" }
                    ]

I am starting aspnet core studies and could not display the data in the datatable.

Thanks a lot for the help. I do not speak English and I used the translator, forgive me any mistakes.

Marcelo

Replies

  • marcelovbamarcelovba Posts: 2Questions: 0Answers: 0

    Solution

    Put all fields in lowercase

    "columns": [
    { "data": "id" },
    { "data": "nomeFuncionario" },
    { "data": "endereco" },
    { "data": "funcao" },
    { "data": "email" },
    { "data": "sexo" }
    ]

  • allanallan Posts: 61,722Questions: 1Answers: 10,108 Site admin

    That's interesting. it would typically match whatever your database is in (although it is possible to alias the column names if you prefer).

    Thanks for posting back and good to hear you've got it working.

    Allan

This discussion has been closed.