Like clause

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • StefanPienaar
    New Member
    • Nov 2007
    • 17

    Like clause

    Hi

    I have a windows application with an Access database where I execute the following:

    cmd.CommandText = "SELECT Id FROM Users WHERE surname LIKE \"p*\"";

    I'm trying to find all users who's surname starts with "P".

    When I fill a dataset using the above no results are returned but when I take that exact string and run it directly in Access it returns the correct Id.

    Any ideas why (or how if im doing it incorrecly) no data is being returned? The connection and everything else is fine because if I do a simple SELECT id FROM users it returns records.

    I have promised myself to never use access as a database again as I have had countless problems thus far where an SQL Express database wouldnt have.

    Thanks
    Stefan
  • Denburt
    Recognized Expert Top Contributor
    • Mar 2007
    • 1356

    #2
    Try the following:

    cmd.CommandText = "SELECT Id FROM Users WHERE surname LIKE 'p*'"

    or

    cmd.CommandText = "SELECT Id FROM Users WHERE surname LIKE ""p*"""

    Comment

    • StefanPienaar
      New Member
      • Nov 2007
      • 17

      #3
      Hi Denburt

      Thanks for the reply but the results are the same :(

      Comment

      • Jim Doherty
        Recognized Expert Contributor
        • Aug 2007
        • 897

        #4
        Originally posted by StefanPienaar
        Hi Denburt

        Thanks for the reply but the results are the same :(
        Hmm.. Stefan me thinks ansii

        try the percent sign instead of asterisk

        Jim

        Comment

        • StefanPienaar
          New Member
          • Nov 2007
          • 17

          #5
          Hi Jim

          Thanks for the quick response but I've opted to rather fill my grid with the entire recordset and then filter it programmaticall y with c# using a dataview.

          Thanks.
          Stefan

          Comment

          Working...