CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 25

Threaded View

  1. #8
    Join Date
    Apr 2005
    Posts
    151

    Re: MFC : searching a database for the second time

    I just read the MSDN and came up with this solution (but the same problem again )

    Code:
    HRESULT CPersonen::ZoekID(int nID)
    {
    	CString strID ;						// needed to convert the ID
    
    	m_pDB->m_strFilter = "" ;			// reset filter
    
    	if (!m_pDB->CanRestart())
    		return S_FALSE ;				// Unable to requery
    	else
    		if (!m_pDB->Requery())
    			return S_FALSE ;			// requery failed
    		else
    			{
    	
    				strID.Format("%d", nID) ;			// convert ID to CString
    
    				CString strFilter  = "ID = " ;
    				strFilter += strID  ;
    		
    				m_pDB->m_strFilter = strFilter ;
    	
    				MessageBox(NULL, m_pDB->m_strFilter, "Filter", MB_OK) ;
    
    				if (!m_pDB->CanRestart())
    					return S_FALSE ;				// Unable to requery
    				else
    					if (!m_pDB->Requery())
    						return S_FALSE ;			// requery failed
    					else
    						return S_OK ;
    			}
    }
    this is the function that I use to search for an ID :
    First I set the strFilter to "", so I get all my records.
    Then I set the strFilter to "ID = number"

    Now when I click the first time on a name I call this function and a message box appears with the strFilter which says "ID = 1" (everything correct!)
    BUT when I check the current record, it's ID is -842150451!!!
    Anyway, now when I press a button "more..." I get a dialog box with more info on that person, when I click OK on that dialog box I return to my main dialog box (with the textbox with the address in it)
    Now when I select another person, the correct address is showed again, when I select another person, it stays the same address again (untill I open/close that 2nd dialogbox)

    so to make a long story short
    I pass on the right filter! But the same record is shown (or the very first time, a totally wrong record is shown (ID = -842150451))
    I hope my explanation makes sense...
    Last edited by da_cobra; May 4th, 2005 at 12:55 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured