请教:在VC中如何用ADO来动态获得数据库中的所有表名? 在VC中用ADO的connection与数据库连接好之后,如何来动态获得数据库中的所有表名?比较急。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 执行 Select name from sysobjects where tpye='U' (如果是SQL 的话) select All_table_name from * 怎么我试验的结果是两种都不行呢?我所知道的一种方法是用adox(即ado extension) Select name from sysobjects where type='U' 此种方法只适用于sqlserver 在SQL服务器上打开事件捕捉,然后打开数据库服务器,接着打开其中一个数据库,再打开表,你就可以看到SQL到底用了什么命令了。 void OpenSchemaX() { // Define ADO object pointers. // Initialize pointers on define. // These are in the ADODB:: namespace. _ConnectionPtr pConnection = NULL; _RecordsetPtr pRstSchema = NULL; //Other Variables HRESULT hr = S_OK; _bstr_t strCnn("Provider=sqloledb;Data Source=MyServer;" "Initial Catalog=pubs;Integrated Security=SSPI;"); try { // Open connection. TESTHR(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); _bstr_t table_type = pRstSchema->Fields-> GetItem("TABLE_TYPE")->Value; printf("Table type: %s\n\n",(LPCSTR) table_type); pRstSchema->MoveNext(); int intLine = intLine + 1; if (intLine % 5 == 0) { printf("\nPress any key to continue..."); getch(); //Clear the screen for the next display system("cls"); } } // Clean up objects before exit. pRstSchema->Close(); pConnection->Close(); } catch (_com_error &e) { // Notify the user of errors if any. // Pass a connection pointer accessed from the Connection. PrintProviderError(pConnection); PrintComError(e); }} 如果是SQLSERVERSelect name from master.dbo.sysobjects where tpye='U' oracle数据库:select * from user_tables FieldsPtr pField=NULL;pField=pRecordset->GetFields();for(int intFields=0;intFields<(int)pField->GetCount();intFields++){ vtIndex.iVal=intFields; (LPCSTR) pField->GetItem(vtIndex)->GetName()} 请教如何从ICONINFO结构中得到鼠标光标的位图? variant_t 插入资源问题 怎么扫描exe的输出表,看他调用了那些dll?有相关的例子没? 用vc控制excel表,把结构相同的表的记录都追加到一张表中,现在copy出现问题!!请教大家! 关于Release和Debug的问题 我发誓:假期一定搞定windows程序设计!!! 怎样快速学好VC VC跳转时光标总相差几行 特级大问题,请教各位大虾. 使用HTTP上传文件? 今天是1月8日,懷念周總理!!
我所知道的一种方法是用adox(即ado extension)
此种方法只适用于sqlserver
{
// Define ADO object pointers.
// Initialize pointers on define.
// These are in the ADODB:: namespace.
_ConnectionPtr pConnection = NULL;
_RecordsetPtr pRstSchema = NULL; //Other Variables
HRESULT hr = S_OK; _bstr_t strCnn("Provider=sqloledb;Data Source=MyServer;"
"Initial Catalog=pubs;Integrated Security=SSPI;"); try
{
// Open connection.
TESTHR(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); _bstr_t table_type = pRstSchema->Fields->
GetItem("TABLE_TYPE")->Value; printf("Table type: %s\n\n",(LPCSTR) table_type); pRstSchema->MoveNext(); int intLine = intLine + 1;
if (intLine % 5 == 0)
{
printf("\nPress any key to continue...");
getch();
//Clear the screen for the next display
system("cls");
}
}
// Clean up objects before exit.
pRstSchema->Close();
pConnection->Close();
} catch (_com_error &e)
{
// Notify the user of errors if any.
// Pass a connection pointer accessed from the Connection.
PrintProviderError(pConnection);
PrintComError(e);
}
}
pField=pRecordset->GetFields();
for(int intFields=0;intFields<(int)pField->GetCount();intFields++)
{
vtIndex.iVal=intFields;
(LPCSTR) pField->GetItem(vtIndex)->GetName()
}