Issue 61 in linqtoexcel: doesn't work with System.String functions?

41 views
Skip to first unread message

linqt...@googlecode.com

unread,
Feb 10, 2012, 4:30:52 PM2/10/12
to linqt...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 61 by dalega...@gmail.com: doesn't work with System.String
functions?
http://code.google.com/p/linqtoexcel/issues/detail?id=61

What steps will reproduce the problem?

Something like this works:

(assuming one of the values of "code" is "hello")

my_string="hello";

var dr = (from r in excel.Worksheet()
where my_string ==(r["code"])
select r).FirstOrDefault();

but THIS, does not:

var dr = (from r in excel.Worksheet()
where my_string.Contains(r["code"])
select r).FirstOrDefault();

this does not find a match. :-(

Using this on Windows 2008 R2, 64-bit.

Man, this is so cool. close, but no cigar for my application.


linqt...@googlecode.com

unread,
Feb 10, 2012, 5:27:26 PM2/10/12
to linqt...@googlegroups.com
Updates:
Status: Done

Comment #1 on issue 61 by paulyo...@gmail.com: doesn't work with
System.String functions?
http://code.google.com/p/linqtoexcel/issues/detail?id=61

where my_string.Contains(r["code"]) creates an invalid SQL statement.
(SELECT * FROM Worksheet WHERE "hello" LIKE code)

You can swap the statement though.

where r["code"].Contains(my_string)

which creates this valid SQL statement: SELECT * FROM Worksheet WHERE code
LIKE '%hello%'

bubuli

unread,
Feb 10, 2012, 10:07:14 PM2/10/12
to Linq To Excel
no, not really. come on, i would have figured that out.

what if:

my_string = "hello world";

var dr = (from r in excel.Worksheet()
where my_string.Contains(r["code"])
select r).FirstOrDefault();

i would want this to return something.

On Feb 10, 5:27 pm, linqtoex...@googlecode.com wrote:
> Updates:
>         Status: Done
>
> Comment #1 on issue 61 by paulyo...@gmail.com: doesn't work with
> System.String functions?http://code.google.com/p/linqtoexcel/issues/detail?id=61

Paul Yoder

unread,
Feb 10, 2012, 10:17:18 PM2/10/12
to linqt...@googlegroups.com
Then you will have to retrieve all the data from excel first and cast it to an in-memory list and then perform your where clause.

my_string  = "hello world";

var dr = (from r in excel.Worksheet().ToList()
          where my_string.Contains(r["code"])
          select r).FirstOrDefault();

If you have a better solution then submit a patch request.

bubuli

unread,
Feb 11, 2012, 10:35:25 AM2/11/12
to Linq To Excel
indeed, this is the workaround..i realized that this is not a
limitation of the library, but instead this is due to the fact that
the Excel driver doesn't have the facility to do this type of query...

thanks!
Reply all
Reply to author
Forward
0 new messages