[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

C++ and ADODB- Retreiving all the fields of a row with Recordset

Posted on 2007-07-20
6
Medium Priority
?
1,120 Views
Last Modified: 2008-03-03
hi all,
I have to make an application which would talk to two databases : Sybase and Oracle and check whether all the fields in all the tables in both the databases are in sync.
The issue is I am unable to retreive all the columns with the recordset. I found many examples and code snippets on the net which retrieves specific column  of each row using bstr = recordset->field->item->value. this is not feasible since the tables differ in their number of columns and some of them have upto 20 columns.
Is there a way I can get all the coulmns of each row print it on the output.
I would later write a parser which would compare the output from the tables across sybase and oracle.
0
Comment
Question by:mparam
  • 2
  • 2
5 Comments
 
LVL 25

Accepted Solution

by:
clockwatcher earned 500 total points
ID: 19533849
Here's a sample I wrote for another question.

void DumpRS(ADODB::_RecordsetPtr rs)
{

     _variant_t index;
     index.vt = VT_I2;

     int fieldcount = (int) rs->Fields->GetCount();

     for (index.iVal =0; index.iVal < fieldcount; index.iVal++)
     {
          cout << rs->Fields->GetItem(index)->GetName() << "^";
     }
     cout << endl;
         
     while (! rs->adoEOF)
     {
          for (index.iVal = 0; index.iVal < fieldcount; index.iVal++)
          {
               ADODB::FieldPtr f = rs->Fields->GetItem(index);
               _variant_t val = f->Value;

               if (val.vt == VT_NULL)
               {
                    val = L"NULL";
               }

               cout << _bstr_t(val) << "^" ;
          }

          cout << endl;
          rs->MoveNext();
     }
     
}
0
 
LVL 1

Author Comment

by:mparam
ID: 19538873
thanks for providing a soln. i will try it and revert.
0
 
LVL 1

Author Comment

by:mparam
ID: 19545294
On trying to compile the code I get the following errors at line 2. could you please help?
C:\my program\dld\seccompas\database.cpp(102) : error C2065: 'adOpenStatic' : undeclared identifier
C:\my program\dld\seccompas\database.cpp(102) : error C2065: 'adLockOptimistic' : undeclared identifier
C:\my program\dld\seccompas\database.cpp(102) : error C2065: 'adCmdTable' : undeclared identifier
C:\my program\dld\seccompas\database.cpp(103) : error C2065: 'adCmdText' : undeclared identifier
line1             dbrs.CreateInstance("ADODB.Recordset");
line2             dbrs->Open (table_name, _variant_t((IDispatch *) dbcn,true), adOpenStatic, adLockOptimistic, adCmdTable);
0
 
LVL 25

Expert Comment

by:clockwatcher
ID: 19548828
To use those constants, you'll need to specify the namespace :

  ADODB::adOpenStatic

Or specify no namespace on your import:

  #import "C:\Program Files\Common Files\System\ado\msado15.dll" rename("EOF","adoEOF") no_namespace
 

0
 
LVL 1

Expert Comment

by:Computer101
ID: 20210721
Forced accept.

Computer101
EE Admin
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying 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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

830 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