Problem with where in LinqToExcel

3

I'm using LinqToExcel to read the data in a book, and it works fine, now what I'm trying to do is put a clause where, to get cleaner data.

I have this

var resultado = (from row in book.Worksheet(NombreSheet)                           
                         let item = new Clases.Comprobante.Comprobante
{
    //Asignaciones por aqui y por alla
}
select item).ToList();

As I said, this works well, and it brings me all the information that is on the excel sheet and makes a Proof item. The idea is to put a clause where for the data that I throw is already clean, and not clean it later.

Within that sheet, I have several columns, one of them is called ACTIVE, with a value of 1 or 0, depending on the case, what I want to try is this

var resultado = (from row in book.Worksheet(NombreSheet)
                             where row["ACTIVO"].Cast<string>() == "1"                     
                             let item = new Clases.Comprobante.Comprobante
{
     //Asignaciones por aqui y por alla
}
select item).ToList();

That only the object creates me if the ACTIVE column of the line contains a 1.

If I try this, it gives me this exception "The data types do not match in the criteria expression." apart from an error in the debug and something from the COM ....

Any ideas?

Greetings

    
asked by Archer_A 29.04.2016 в 00:00
source

2 answers

0

.Cast<string>() what it does is treat it as row["ACTIVO"] as an IEnumerable and try to convert every char to string , what you should probably do is just a normal cast (string)row["ACTIVO"] and "1" as a string.

var resultado = (from row in book.Worksheet(NombreSheet)
                             where (string)row["ACTIVO"] == "1"                     
                             let item = new Clases.Comprobante.Comprobante
{
     //Asignaciones por aqui y por alla
}
select item).ToList();
    
answered by 29.04.2016 в 00:07
0

You can try the following code:

var resultado = book.Worksheet(NombreSheet.finsAll(Obj => (string)obj["ACTIVO"] == "1");
    
answered by 24.03.2017 в 07:10