Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working on ADO database programmin in vc++ (VC6),i have a problem to get the all table name from MS access database file (*.mdb file) using vc++ with ADO.
e.g. if database table contains table1, table2, and table3 tables then i need to display all table name.
I tried the following code i didn't get table name.
C#
   _ConnectionPtr pConnection = NULL;
   _RecordsetPtr pRstSchema = NULL;

   _bstr_t strCnn("Driver={Microsoft Access Driver (*.mdb)};"
           "Dbq=c:\\dbaccess.mdb;Uid=;Pwd=;");

      pConnection.CreateInstance(__uuidof(Connection));
      pConnection->Open (strCnn, "", "", adConnectUnspecified);

      pRstSchema = pConnection->OpenSchema(adSchemaTables);

    while ( !(pRstSchema->EndOfFile) ) {
         _bstr_t table_name = pRstSchema->Fields->GetItem("TABLE_NAME")->Value;

         printf("Table Name: %s\n",(LPCSTR) table_name);
}


But by using above code it is displaying like this Mysysobj instead of table1,table2... etc.

So please tell me where i am doing mistake or give some other methods to do this.
Posted
Updated 25-Mar-12 23:13pm
v2
Comments
Sergey Chepurin 26-Mar-12 6:03am    
Add MoveNext() as was proposed below.
These sources can help "HOWTO: Using the ADO OpenSchema Method from Visual C++": http://support.microsoft.com/kb/182831 and "OpenSchema function "http://www.codeproject.com/Articles/1075/A-set-of-ADO-classes-version-2-20#OpenSchema

1 solution

Insert this at the end of the while loop:
C++
pRstSchema->MoveNext();

Otherwise, you have an endless loop showing only the first table name.

The MSys* tables are MS Access internal tables. If you want to exclude them from being shown, just check for names beginning with 'MSys'.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900