Passing a _RecordsetPtr object as a function parameter??? 
Author Message
 Passing a _RecordsetPtr object as a function parameter???

Dear Reader,

I have the function Query() which takes a parameter called pRecordSet of the
type _RecordsetPtr. The function Query() does a query on a particular table
and returns the results in the pRecordSet variable (well it seems like he is
doing this).

I call this function like this:

database->Query( pRecordSet, pTable->name, stringSQL );

/***** Query *****/
bool CDatabase::Query( ADODB:: _RecordsetPtr pRecordSet, TCHAR* table,
TCHAR* stringSQL )
{
  TCHAR   commandString[STRING_COLUMNS + DB_SQL_STRING];
  int     records;

  _stprintf( commandString, DB_SQL_SELECT_WHERE, _TEXT("*"), table,
stringSQL );
  pCommand->CommandText = _bstr_t( commandString );

  try
  {
    pRecordSet = pCommand->Execute( &vtMissing, &vtMissing,
ADODB::adCmdText );
  }
  catch ( _com_error &exception )
  {
    return (false);
  }

  records = GetRecordCount( pRecordSet );  //First count

  return (true);

Quote:
}

Now when I return from the function call to query I also check the total
records:

records = database->GetRecordCount( pRecordSet ); //Second count

Somehow I think that the recordSet is passed by value and not by reference.
How can I pass this recordset by reference?? Do I have to wrap it in a
variant and how?? Or is there another solution.

Thank you,

Johan Machielse



Tue, 12 Oct 2004 22:21:04 GMT  
 Passing a _RecordsetPtr object as a function parameter???
Hi Philips,

_RecordsetPtr is a COM smart pointer generated by "#import" directive. You
can try to pass it by reference:
bool CDatabase::Query(RecordsetPtr& pRecordSet, TCHAR* strTable, TCHAR*
strSQL);

Hope it helps.

This posting is provided "AS IS" with no warranties, and confers no rights.

Regards,

Bill Cheng
Microsoft Support Engineer
--------------------

| Newsgroups: microsoft.public.vc.database
| Subject: Passing a _RecordsetPtr object as a function parameter???
| Date: Fri, 26 Apr 2002 16:21:04 +0200
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 5.50.4522.1200
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200
| Lines: 51

| NNTP-Posting-Host: gw-ehv05.pnl.philips.com
| X-Trace: 1019830898 read-nat.news.nl.uu.net 230 212.153.190.4

| Path:
cpmsftngxa07!tkmsftngxs01!tkmsftngp01!newsfeed00.sul.t-online.de!t-online.de
!fr.usenet-edu.net!usenet-edu.net!bnewspeer01.bru.ops.eu.uu.net!bnewsifeed03
bru.ops.eu.uu.net!bnewspost00.bru.ops.eu.uu.net!emea.uu.net!read-nat.news.n
l.uu.net!not-for-mail
| Xref: cpmsftngxa07 microsoft.public.vc.database:26615
| X-Tomcat-NG: microsoft.public.vc.database
|
| Dear Reader,
|
| I have the function Query() which takes a parameter called pRecordSet of
the
| type _RecordsetPtr. The function Query() does a query on a particular
table
| and returns the results in the pRecordSet variable (well it seems like he
is
| doing this).
|
| I call this function like this:
|
| database->Query( pRecordSet, pTable->name, stringSQL );
|
| /***** Query *****/
| bool CDatabase::Query( ADODB:: _RecordsetPtr pRecordSet, TCHAR* table,
| TCHAR* stringSQL )
| {
|   TCHAR   commandString[STRING_COLUMNS + DB_SQL_STRING];
|   int     records;
|
|   _stprintf( commandString, DB_SQL_SELECT_WHERE, _TEXT("*"), table,
| stringSQL );
|   pCommand->CommandText = _bstr_t( commandString );
|
|   try
|   {
|     pRecordSet = pCommand->Execute( &vtMissing, &vtMissing,
| ADODB::adCmdText );
|   }
|   catch ( _com_error &exception )
|   {
|     return (false);
|   }
|
|   records = GetRecordCount( pRecordSet );  //First count
|
|   return (true);
| }
|
| Now when I return from the function call to query I also check the total
| records:
|
| records = database->GetRecordCount( pRecordSet ); //Second count
|
| Somehow I think that the recordSet is passed by value and not by
reference.
| How can I pass this recordset by reference?? Do I have to wrap it in a
| variant and how?? Or is there another solution.
|
| Thank you,
|
| Johan Machielse
|
|
|



Thu, 14 Oct 2004 17:27:47 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Passing COM objects as parameters to other COM objects

2. Passing COM objects as parameters to other COM objects

3. Passing C++ Class Member Function to as a C Callback Function Parameter

4. object is resolved pointer to the object when passed to a function

5. to pass object as a parameter in method of interface

6. Passing a COM object as a parameter?

7. Newbie : passing objects as parameters?

8. Passing VB dictionaries as parameters to ATL COM objects

9. Passing a RecordsetPtr to a thread in c++

10. How to pass _ConnectionPtr to _RecordsetPtr->Open() ?

11. VC++ pass object parameter to VB ActiveX DLL

12. Passing Object As Parameter ?

 

 
Powered by phpBB® Forum Software