Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Applying a LIKE with ignoring the case

Applying a LIKE with ignoring the case

Scheduled Pinned Locked Moved ASP.NET
databasehelpcsharpasp-netquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DotNet_Newbie
    wrote on last edited by
    #1

    Hello all Gurus, I have a quick question, I have an ASP.Net application and doing some database connections and Queries using an OleDbAdapter/Connection, now what I’m having a problem with is: I read in a user input (first few letters of a name) then I try to query the database selecting any FirstName that is LIKE the input but ignoring the case. The problem is I can’t control how many characters the user will enter of the Name, and their case, in the mean while some of the data base entries are in small letters and some are CAPS, basically I’m trying to use the LIKE clause with ignoring the case. So far I have something like that strQuery = "SELECT * FROM MyTabl WHERE FirstName LIKE 'A%' OR FirstName LIKE 'a%' 'This will alow me to select all FirstNames starting with a CAP 'A' or 'a', but that is a set text (the A) I need to compare againist the input. What I'm hopping to get to is somthing that would give me a result of strQuery = "SELECT * FROM MyTabl WHERE (ToUperCase FirstName) LIKE (ToUperCase txtBx.Text) 'if in Reguler VB I would have done somting like that: "SELECT * FROM MyTabl WHERE UPPER(FirstName) LIKE UCase(textLetter.Text) I know that this not a Syntax but that is the Idea or Logic I'm trying to apply, So can I use your help here. Thanks in advance for your help.

    A 1 Reply Last reply
    0
    • D DotNet_Newbie

      Hello all Gurus, I have a quick question, I have an ASP.Net application and doing some database connections and Queries using an OleDbAdapter/Connection, now what I’m having a problem with is: I read in a user input (first few letters of a name) then I try to query the database selecting any FirstName that is LIKE the input but ignoring the case. The problem is I can’t control how many characters the user will enter of the Name, and their case, in the mean while some of the data base entries are in small letters and some are CAPS, basically I’m trying to use the LIKE clause with ignoring the case. So far I have something like that strQuery = "SELECT * FROM MyTabl WHERE FirstName LIKE 'A%' OR FirstName LIKE 'a%' 'This will alow me to select all FirstNames starting with a CAP 'A' or 'a', but that is a set text (the A) I need to compare againist the input. What I'm hopping to get to is somthing that would give me a result of strQuery = "SELECT * FROM MyTabl WHERE (ToUperCase FirstName) LIKE (ToUperCase txtBx.Text) 'if in Reguler VB I would have done somting like that: "SELECT * FROM MyTabl WHERE UPPER(FirstName) LIKE UCase(textLetter.Text) I know that this not a Syntax but that is the Idea or Logic I'm trying to apply, So can I use your help here. Thanks in advance for your help.

      A Offline
      A Offline
      Asad Hussain
      wrote on last edited by
      #2

      All you need to do is run a case insensitive query. You can do this by converting the string you want to search into upper case and the result to upper case also. e.g. dim searchString as string = UCase(textLetter.text) dim qryString as string = "SELECT * FROM MyTabl WHERE UPPER(FirstName) LIKE '" & searchString & "%'"

      D 1 Reply Last reply
      0
      • A Asad Hussain

        All you need to do is run a case insensitive query. You can do this by converting the string you want to search into upper case and the result to upper case also. e.g. dim searchString as string = UCase(textLetter.text) dim qryString as string = "SELECT * FROM MyTabl WHERE UPPER(FirstName) LIKE '" & searchString & "%'"

        D Offline
        D Offline
        DotNet_Newbie
        wrote on last edited by
        #3

        Thank you very much, It worked. I tried several things but never this format '" & searchString & "%' can I ask you for a quick explanation of its format. Thanks A lot

        A 1 Reply Last reply
        0
        • D DotNet_Newbie

          Thank you very much, It worked. I tried several things but never this format '" & searchString & "%' can I ask you for a quick explanation of its format. Thanks A lot

          A Offline
          A Offline
          Asad Hussain
          wrote on last edited by
          #4

          Strings have to enclosed in quotation marks in an sql query. For example, you cannot do SELECT * FROM table WHERE text = whatever you must enclose whatever in single quotes SELECT * FROM table WHERE text = 'whatever' Now if you are building your own string in a variable, you need to explicitly enclose them in single quotes.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups