Search Function Help (database support)

Posted on 2004-08-25
Last Modified: 2013-11-20
I have created a Database application in Visual C++ 6.0 through the MFC application wizard. I have almost completed my application except for a few touch ups.  So far i have been able to search only if i get an exact match by using m_strFilter which is a function of CRecordSet class (function made available for me through the mfc application wizard).  I would like to be able to filter partial matches as well.

Application Interface:

example: I will search the term "Summer" in the field called RecipeName
I will get records with the Recipe Name of Summer Breeze, Summer Baybreeze, Summer Dream and so on..
so all the records i would like filtered will at least contain "Summer" in the RecipeName field.

Question: How can I search my records and filter partial matches as well as exact matches?

App info: MFC SDI with database support

here is part of the code that calls my search button:

void CDrinkRecipesView::OnSearchbutton2()
      CString m_Input="";
      GetDlgItemText(IDC_SEARCHEDIT, m_Input);

      m_pSet->m_strFilter = "RecipeName = ?";
      m_pSet->m_RecipeNameParam = m_Input;
      if (m_pSet->IsBOF())
            m_pSet->m_strFilter = "RecipeName = RecipeName";
            AfxMessageBox("Record not found!");


Additional info: Here is the web address to all of my files

Thanks for your help
Question by:cshoun
  • 2
  • 2
LVL 44

Expert Comment

ID: 11895701
instead of
m_pSet->m_strFilter = "RecipeName = ?";
m_pSet->m_strFilter = "RecipeName = 'summer*'";

note for searching on a string you need the single quotes, the * is a wildcard to match else it finds only the exact string.

Author Comment

ID: 11895846
just tried that it still only finds exact matches and it excepts the * as part of search criteria
LVL 44

Accepted Solution

AndyAinscow earned 500 total points
ID: 11900088
my mistake (end of a hard day)
m_pSet->m_strFilter = "RecipeName LIKE 'summer*'";

also the wildcard can be provider dependant, alternative could be %

Author Comment

ID: 11900194
Thanks I have found though that the star doesn't work...but your % does

example: m_pSet->m_strFilter = "RecipeName LIKE '%summer%'";
             will take all summer matches

m_pSet->m_strFilter = "RecipeName LIKE '%summer'";
will only take summer matches when the field ends with summer!

m_pSet->m_strFilter = "RecipeName LIKE 'summer%'";
will only take summer matches when the field begins with summer!

i gave up on an answer so I just started writing my own filter...which was taking forever...Thank god i haven't saved yet :)

A thousand thanks to you

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Adapt this command to show who installed 29 108
Prevent this page from creating additional dialogs. 3 507
conditional code and condition difference 9 82
either24  challenge 19 95
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now