?
Solved

Automatic renew recordset data in VC++ ADO

Posted on 2007-10-03
4
Medium Priority
?
985 Views
Last Modified: 2008-01-09
VC++ 6.0, SQL Server 2000
I build the recordset of rsVipCard, and just want to find the 'CardID' in database.
But when the data is updated by other user in SQL Server 2000, the rsVipCard not update automatically.
What is the problem?

I use the module of ADO2.CPP
// MODULE: Ado2.cpp
// AUTHOR: Carlos Antollini <cantollini@hotmail.com>
// Copyright (c) 2001-2004. All Rights Reserved.
// Date: August 01, 2005
My code is something like this:

m_pRecordset->CursorLocation = adUseClient
m_pRecordset->CursorType = adOpenDynamic
CADORecordset rsVipCard;
CADODatabase dbVipCard;
rsVipCard = CADORecordset(&dbVipCard);
rsVipCard.Open("select * from VipCard", CADORecordset::openQuery)
strSQL="VipCardID=1245678";
if (rsVipCard.FindFirst (strSQL)!=0)
  //found
else
 //not found


//
// MODULE: Ado2.cpp
//
// AUTHOR: Carlos Antollini <cantollini@hotmail.com>
//
// Copyright (c) 2001-2004. All Rights Reserved.
//
// Date: August 01, 2005
//
// Version 2.20

BOOL CADORecordset::Open(_ConnectionPtr mpdb, LPCTSTR lpstrExec, int nOption)
{      
      Close();
      
      if(strcmp(lpstrExec, _T("")) != 0)
            m_strQuery = lpstrExec;

      ASSERT(!m_strQuery.IsEmpty());

      if(m_pConnection == NULL)
            m_pConnection = mpdb;

      m_strQuery.TrimLeft();
      BOOL bIsSelect = m_strQuery.Mid(0, strlen("Select ")).CompareNoCase("select ") == 0 && nOption == openUnknown;

      try
      {
            m_pRecordset->CursorType = adOpenDynamic;
                  

            m_pRecordset->CursorLocation = adUseClient;
            if(bIsSelect || nOption == openQuery || nOption == openUnknown)
                  m_pRecordset->Open((LPCSTR)m_strQuery, _variant_t((IDispatch*)mpdb, TRUE),
                                          adOpenDynamic, adLockOptimistic, adCmdUnknown);  ////huang 2007-09-02 change from adOpenStatic to Dynamic

                  else if(nOption == openTable)
                  m_pRecordset->Open((LPCSTR)m_strQuery, _variant_t((IDispatch*)mpdb, TRUE),
                                          adOpenKeyset, adLockOptimistic, adCmdTable);
            else if(nOption == openStoredProc)
            {
                  m_pCmd->ActiveConnection = mpdb;
                  m_pCmd->CommandText = _bstr_t(m_strQuery);
                  m_pCmd->CommandType = adCmdStoredProc;
                  m_pConnection->CursorLocation = adUseClient;
                  
                  m_pRecordset = m_pCmd->Execute(NULL, NULL, adCmdText);
            }
            else
            {
                  TRACE( "Unknown parameter. %d", nOption);
                  return FALSE;
            }
      }
      catch(_com_error &e)
      {
            dump_com_error(e);
            return FALSE;
      }

      return m_pRecordset != NULL && m_pRecordset->GetState()!= adStateClosed;
}


BOOL CADORecordset::FindFirst(LPCTSTR lpFind)
{
      m_pRecordset->MoveFirst();
      return Find(lpFind);
}


BOOL CADORecordset::Find(LPCTSTR lpFind, int nSearchDirection)
{

      m_strFind = lpFind;
      m_nSearchDirection = nSearchDirection;

      ASSERT(!m_strFind.IsEmpty());

      if(m_nSearchDirection == searchForward)
      {
            m_pRecordset->Find(_bstr_t(m_strFind), 0, adSearchForward, "");
            if(!IsEof())
            {
                  m_varBookFind = m_pRecordset->Bookmark;
                  return TRUE;
            }
      }
      else if(m_nSearchDirection == searchBackward)
      {
            m_pRecordset->Find(_bstr_t(m_strFind), 0, adSearchBackward, "");
            if(!IsBof())
            {
                  m_varBookFind = m_pRecordset->Bookmark;
                  return TRUE;
            }
      }
      else
      {
            TRACE("Unknown parameter. %d", nSearchDirection);
            m_nSearchDirection = searchForward;
      }
      return FALSE;
}
0
Comment
Question by:hxb
  • 2
4 Comments
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 20011748
check this link, http://www.codeproject.com/cs/database/chatter.asp. This talks about the event notification on data change.
0
 
LVL 45

Accepted Solution

by:
AndyAinscow earned 1500 total points
ID: 20012124
>>m_pRecordset->CursorLocation = adUseClient

Shouldn't that be a server side cursor ?

(You might need to rerun the query to get the latest changes.)
0
 

Author Comment

by:hxb
ID: 20018754
I have set  m_pRecordset->CursorType = adOpenDynamic, is it means when there is new update in server side, it will info the ado recordset client?

0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 20019936
Unless I misunderstand the cursor functionality a client side cursor will not 'see' changes made to the server automatically.  Having the cursor as a server side cursor doesn't mean it will work however - the database drivers would also have to support the server side dynamic cursor.  (With SQL 2000 that support should exist)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

840 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