Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Search Function Help (database support)

Posted on 2004-08-25
4
Medium Priority
?
255 Views
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: http://www.public.iastate.edu/~cshoun/DrinkRecipes.jpg

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:

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

      m_pSet->m_strFilter = "RecipeName = ?";
      m_pSet->m_RecipeNameParam = m_Input;
      m_pSet->Requery();
      
      if (m_pSet->IsBOF())
      {      
            m_pSet->m_strFilter = "RecipeName = RecipeName";
            m_pSet->Requery();
            
            AfxMessageBox("Record not found!");
            UpdateData(FALSE);
            m_ctlSearchEdit.SetFocus();
            m_ctlSearchEdit.SetSel(0,-1);
      }
            
      else
      {
            UpdateData(FALSE);
            m_ctlSearchEdit.SetSel(0,-1);
            m_ctlSearchEdit.Clear();
            m_ctlSearchEdit.SetFocus();
      }

}

Additional info: Here is the web address to all of my files http://www.public.iastate.edu/~cshoun/DrinkRecipes/

Thanks for your help
0
Comment
Question by:cshoun
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 11895701
instead of
m_pSet->m_strFilter = "RecipeName = ?";
try
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.
0
 

Author Comment

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

Accepted Solution

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

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

Author Comment

by:cshoun
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
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

636 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