Case sensitivity with ADO.NET and Excel
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: Case sensitivity with ADO.NET and Excel

  1. #1
    Join Date
    Jul 2009
    Posts
    5

    Case sensitivity with ADO.NET and Excel

    Hi
    I'm running a 'LIKE' query against an Excel worksheet using ADO.NET and its proving to be case sensitive. I really want it to be case insensitive (which it should be according to all the info I can find) - does anyone have any ideas how I can achieve that?

    My connect string is: Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyFile.xls;Extended Properties="Excel 8.0;HDR=YES;IMEX=1"

    My query is: SELECT * FROM [Sheet1$] WHERE Chassis LIKE '%Foo%'

    This does match Chassis entries of 'Foo', but not 'foo', 'FOO', etc.

    Thanks in advance

    Steve H

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,875

    Re: Case sensitivity with ADO.NET and Excel

    Seems like something is wrong. Read this link
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jul 2009
    Posts
    5

    Re: Case sensitivity with ADO.NET and Excel

    Thanks for the link. The content seems to focus purely on SQL Server and my problem is with Excel. I did try adding a COLLATE Latin1_General_CI_AS clause to the WHERE condition but it fails with an unhelpful error (E_Failxxxx).

    I'm not using Excel out of choice - its what the customer requires due to their operational setup and hosting situation. If I could move the data to a proper DB then I'd be fine, but I don't have that luxury in this case.

    Any other ideas anyone?

    many thanks,

    Steve H

  4. #4
    Join Date
    Feb 2005
    Location
    Denmark
    Posts
    742

    Re: Case sensitivity with ADO.NET and Excel

    I don't think you have other choice then to compare them case insensitive, meaning convert both to upper case when running your queries.

    Something like:
    SELECT * FROM [Sheet1$] WHERE UPPER(Chassis) LIKE '%FOO%'

    Note, I'm not sure if UPPER works in the SQL to Excel like that, but it would work in other flavors of SQL, but I'm sure a similar function would exists

  5. #5
    Join Date
    Jul 2009
    Posts
    5

    Re: Case sensitivity with ADO.NET and Excel

    I didn't really want to do that as it will hit performance. I'm not sure how the Jet OLE DB driver deals with Excel files but I guess it doesn't really have that much opportunity to optimise operations like this.

    If I can't find any other solution then I will fall back to this approach, but hoping that someone can come up with an alternative!

    thanks,

    Steve H

  6. #6
    Join Date
    Feb 2005
    Location
    Denmark
    Posts
    742

    Re: Case sensitivity with ADO.NET and Excel

    It will indeed be a performance hit, yes.

    Perhaps there's an alternative method of doing this - how often will you read from the excel file? And how's the data used?

    Because if the Excel file is manageable in size, there could perhaps be some merit in just pulling all the (potentially needed) data into your code layer and filter it there?
    As your code layer will be better optimized at running such string manipulation/comparisons?

  7. #7
    Join Date
    Jul 2009
    Posts
    5

    Re: Case sensitivity with ADO.NET and Excel

    Update: This is wierd, but the problem disappeared when the application was deployed from a dev system onto a staging server. Haven't tried the live box yet, but it would seem that case sensitivity is determined by the server build rather than any application settings.

    Thanks for the suggestions that were made, but in light of the discovery that its a system-specific issue I will consider this thread closed.

    Many thanks, Steve H

  8. #8
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,875

    Re: Case sensitivity with ADO.NET and Excel

    That's what my link said.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  9. #9
    Join Date
    Jul 2009
    Posts
    5

    Re: Case sensitivity with ADO.NET and Excel

    Hi - I'm not trying to be picky or ungracious because I really do value all the help I can get, but your link related to SQL Server 2000 configuration rather than the OS-level build issues which I now think are at the heart of my problems. I did try the 'collation' clauses suggested in the article but they gave syntax errors with the OLE DB driver.

    The application I'm developing doesn't use SQL Server at all - in fact the live server won't even have it installed. It would be 10 times easier to code this whole piece if there was a decent DB to work with, but the customer has mandated that the data be held in Excel files on a server with no formal RDBMS installed.

    Thanks for all suggestions though!

    regards

    Steve H

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center