我想连接数据库后把所有表名都列出来方便浏览!
不知道怎么做,有哪位大哥知道的啊!

解决方案 »

  1.   

    connection 对象的 OpenShema()方法
      

  2.   

    我的Blog上有相关的写法...
    虽然我使用Access实验的,SQL的ADO也应该一样~~~
    http://blog.csdn.net/LBPeking/archive/2008/03/29/2229220.aspx
      

  3.   

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

  4.   

    参考如下如何判断access数据库中是否存在某个表的代码(对所有表进行了遍历):STDMETHODIMP CADOTier::get_IsExistTable(BSTR bsTable, long lType, VARIANT_BOOL *pVal)
    {
      ADODB::_RecordsetPtr pRstSchema = NULL;
      pRstSchema = m_connection->OpenSchema(ADODB::adSchemaTables);
      _bstr_t bsTableName(bsTable);
      _bstr_t table_name("");
      _bstr_t table_type("");
      char *pTemp1=NULL,*pTemp2=NULL;
      pTemp1 = _com_util::ConvertBSTRToString(bsTableName);
      pTemp1 = strlwr(pTemp1);
      VARIANT_BOOL b=FALSE;
      while(!(pRstSchema->adoEOF))
      {
        table_name = pRstSchema->Fields->
        GetItem("TABLE_NAME")->Value;
        pTemp2 = _com_util::ConvertBSTRToString(table_name);
        pTemp2 = strlwr(pTemp2);
        table_type = pRstSchema->Fields->
        GetItem("TABLE_TYPE")->Value;
        if (lType == 1) //view type
        {
          if (table_type == _bstr_t("VIEW"))
          {
            if (strcmp(pTemp1,pTemp2)==0)
            b = TRUE;
          }
        }
        if (lType == 0) //table type
        {
          if (table_type == _bstr_t("TABLE"))
          {
            if (strcmp(pTemp1,pTemp2)==0)
            b = TRUE;
          }
        }
        pRstSchema->MoveNext();
      }
      
      // Clean up objects before exit.
      if (pRstSchema)
      if (pRstSchema->State == ADODB::adStateOpen)
      pRstSchema->Close();
      *pVal = b;
      return S_OK;
    }
      

  5.   

    SELECT *
    FROM sysobjects
    WHERE (xtype = 'U') 
    呵呵!找到了!
    SQL