codeice / linqtoexcel

Automatically exported from code.google.com/p/linqtoexcel
0 stars 0 forks source link

Syntax error in query expression #55

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Load up the attached file
2. Try an remove items that have blank strings using the below code

What is the expected output? What do you see instead?
I expect my result set to contain 2 items. However I have 102 with 100 
completely empty. I appreciate this might be some Excel issue but the code that 
tries to remove empty entries falls over.

What version of the product are you using? On what operating system?
1.5.3 however looking at it in Windows explorer it says 1.0.0. I got it from 
NuGet

Please provide any additional information below.
Here is my code:

public class LicenceImport
{
        public string SerialNo { get; set; }
        public string LicenceKey { get; set; }
}

var excel = new ExcelQueryFactory(path);
                var licenceInfo = from c in excel.WorksheetNoHeader()
                                  where !String.IsNullOrWhiteSpace(c[0]) && !String.IsNullOrWhiteSpace(c[11])
                                  select new LicenceImport() { SerialNo = c[0], LicenceKey = c[11] };

var data = licenceInfo.ToList();

The ToList() method results in a System.Data.OleDb.OleDbException Syntax error 
in query expression '([onvert([-1].get_Item(0)] AND 
[onvert([-1].get_Item(11)])'.

Please help!

Original issue reported on code.google.com by jonathan...@gmail.com on 12 Oct 2011 at 2:53

Attachments:

GoogleCodeExporter commented 8 years ago
To get around it I can do:

var licenceInfo = from c in excel.WorksheetNoHeader()
                  select new LicenceImport() { SerialNo = c[0], LicenceKey = c[11] };

var data =  licenceInfo.Where(x => !String.IsNullOrWhiteSpace(x.LicenceKey) && 
!String.IsNullOrWhiteSpace(x.SerialNo)).ToList();

Original comment by jonathan...@gmail.com on 12 Oct 2011 at 3:11

GoogleCodeExporter commented 8 years ago
The OleDb driver doesn't know how to translate String.IsNullOrWhiteSpace, so 
you'll have to remove the where clause to retrieve all the rows to an in memory 
list, and then you can filter the results. This is exactly what you did in your 
workaround, and I'm pretty sure that's the only way to do it.

Original comment by paulyo...@gmail.com on 12 Oct 2011 at 3:39