• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1003
  • Last Modified:

Automatic renew recordset data in VC++ ADO

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
hxb
Asked:
hxb
  • 2
1 Solution
 
Roshan DavisCommented:
check this link, http://www.codeproject.com/cs/database/chatter.asp. This talks about the event notification on data change.
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
>>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
 
hxbAuthor Commented:
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
 
AndyAinscowFreelance programmer / ConsultantCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now