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. General Programming
  3. C / C++ / MFC
  4. Problem with LIKE from MFC

Problem with LIKE from MFC

Scheduled Pinned Locked Moved C / C++ / MFC
databasehelpc++tutorialquestion
3 Posts 3 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Hi! I work with database from MFC (Access).I want to send Sql command. My function recieve parameter and I use variable type CString with format. For example: strSql.Format("SELECT COUNT([TblCatalogList].[CatalogId]) FROM [TblCatalogList] WHERE [TblCatalogList].[PcBoard] LIKE '%s%'",strBoard); But it does not work and failed becouse unknown format.LIKE must have this format,for example LIKE '123%' it means that I want to find string that begin from 123,but how must I write if I have a parameter??? Help me,please with syntax!!!

    D L 2 Replies Last reply
    0
    • L Lost User

      Hi! I work with database from MFC (Access).I want to send Sql command. My function recieve parameter and I use variable type CString with format. For example: strSql.Format("SELECT COUNT([TblCatalogList].[CatalogId]) FROM [TblCatalogList] WHERE [TblCatalogList].[PcBoard] LIKE '%s%'",strBoard); But it does not work and failed becouse unknown format.LIKE must have this format,for example LIKE '123%' it means that I want to find string that begin from 123,but how must I write if I have a parameter??? Help me,please with syntax!!!

      D Offline
      D Offline
      Derek Waters
      wrote on last edited by
      #2

      What does strSql contain after the format statement? I suspect from the example you gave that you'll be missing a percentage and quote sign. This is because the two characters "%'" will be removed from your string. To get a '%' character in a string you need to put two of them (%%):

      strSql.Format("SELECT COUNT([TblCatalogList].[CatalogId]) FROM [TblCatalogList] WHERE [TblCatalogList].[PcBoard] LIKE '%s%%'",strBoard);

      Hope this helps. ------------------------ Derek Waters derek@lj-oz.com

      1 Reply Last reply
      0
      • L Lost User

        Hi! I work with database from MFC (Access).I want to send Sql command. My function recieve parameter and I use variable type CString with format. For example: strSql.Format("SELECT COUNT([TblCatalogList].[CatalogId]) FROM [TblCatalogList] WHERE [TblCatalogList].[PcBoard] LIKE '%s%'",strBoard); But it does not work and failed becouse unknown format.LIKE must have this format,for example LIKE '123%' it means that I want to find string that begin from 123,but how must I write if I have a parameter??? Help me,please with syntax!!!

        L Offline
        L Offline
        Lakitu
        wrote on last edited by
        #3

        To get a literal % sign you'll need to specify it as %% in the format string.


        You know, for kids!

        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