2
This code reads a file Excel
and plays a list, the problem that is occurring is it is returning null, like there’s nothing in the 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;
}
You tried to thresh? You know if he’s not even in
while
? Try to isolate the problem further.– Maniero
Remove the Try catch block to check the error better. Then you can return it.
– Jones