在C ++中的ADO数据库编程中获取表名的问题 [英] Problem to get the table name in ADO database programming in C++
问题描述
我正在使用vc ++(VC6)中的ADO数据库programmin,我在使用vc ++和ADO从MS Access数据库文件(* .mdb文件)中获取所有表名时遇到问题.
例如如果数据库表包含table1,table2和table3表,那么我需要显示所有表名.
我尝试了以下代码,但未获得表名.
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.
_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);
}
但是通过使用上面的代码,它显示的是这样的Mysysobj而不是table1,table2 ...等.
因此,请告诉我我在哪里做错了,或者提供其他一些方法来做到这一点.
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.
推荐答案
在while循环的末尾插入此代码:
Insert this at the end of the while loop:
pRstSchema->MoveNext();
否则,您将无休止地循环,仅显示第一个表名.
MSys * 表是MS Access内部表.如果要从显示中排除它们,只需检查以"MSys"开头的名称.
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''.
这篇关于在C ++中的ADO数据库编程中获取表名的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!