We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

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

mparam
mparam asked
on
Medium Priority
1,366 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.
Comment
Watch Question

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();
     }
     
}

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
thanks for providing a soln. i will try it and revert.

Author

Commented:
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);
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
 

Forced accept.

Computer101
EE Admin
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.