在VC中用ADO的connection与数据库连接好之后,如何来动态获得数据库中的所有表名?比较急。

解决方案 »

  1.   

    执行 Select name from sysobjects where tpye='U' (如果是SQL 的话)
      

  2.   

    select All_table_name from *
      

  3.   

    怎么我试验的结果是两种都不行呢?
    我所知道的一种方法是用adox(即ado extension)
      

  4.   

    Select name from sysobjects where type='U' 
    此种方法只适用于sqlserver
      

  5.   

    在SQL服务器上打开事件捕捉,然后打开数据库服务器,接着打开其中一个数据库,再打开表,你就可以看到SQL到底用了什么命令了。
      

  6.   

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

  7.   

    如果是SQLSERVERSelect name from master.dbo.sysobjects where tpye='U'
      

  8.   

    oracle数据库:select * from user_tables
      

  9.   

    FieldsPtr pField=NULL;
    pField=pRecordset->GetFields();
    for(int intFields=0;intFields<(int)pField->GetCount();intFields++)
    {
    vtIndex.iVal=intFields;
    (LPCSTR) pField->GetItem(vtIndex)->GetName()
    }