Returns Excel in List C # is returning null

2

This code reads a Excel file and throws a list, the problem that is occurring is it is returning null , as if there was nothing in it Excel , but the column names are correct:

string PathConn = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + local + ";" + "Extended Properties=\"Excel 12.0;HDR=YES;\";";
System.Data.OleDb.OleDbConnection conn = new OleDbConnection(PathConn);
string sqlCommand = "Select * From [Plan1$]";
OleDbCommand command = new OleDbCommand(sqlCommand, conn);
List<Entidades> listaComentario = new List<Entidades>();

try
{
    conn.Open();
    OleDbDataReader rd = command.ExecuteReader();

    while (rd.Read())
    {
        listaComentario.Add(new Entidades()
        {
            PNR = rd[System.Configuration.ConfigurationManager.AppSettings["PNR"]].ToString(),
            Status = rd[System.Configuration.ConfigurationManager.AppSettings["Status"]].ToString(),
        });
    }

    if (listaComentario.Count() > 0)
        return listaComentario;
    else
        return null;

}
    
asked by anonymous 01.10.2014 / 17:18

1 answer

2

just to register. I found the problem. I changed my machine, for one that works with a 64-bit processor. The error was falling on Catch, when I debugged, I found the problem.

I was returning "microsoft.ace.oledb.12.0 not registered on the local machine" . To fix it, just install a 64-bit Driver Data Connectivity, which I took at Microsoft's own website: link ,

Thanks to all.

    
06.10.2014 / 23:13