Esse código faz a leitura de um arquivo Excel
e joga uma lista, o problema que está ocorrendo é ele está retornando nulo, como se não houvesse nada no Excel
, porem os nomes das colunas estão corretos:
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;
}
while
? Tente isolar mais o problema.