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;
}