Problem with LIKE from MFC
-
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!!!
-
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!!!
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
-
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!!!