获取ACCESS2000数据库中所有表的名称

2016-02-19 15:48 0 1 收藏

下面是个获取ACCESS2000数据库中所有表的名称教程,撑握了其技术要点,学起来就简单多了。赶紧跟着图老师小编一起来看看吧!

【 tulaoshi.com - 编程语言 】

void OpenSchemaX(TCHAR *TableName)
{
HRESULT hr = S_OK;
  
::CoInitialize(NULL); //初始化Com
  
IADORecordBinding *picRs = NULL;
  
_RecordsetPtr pRstSchema("ADODB.Recordset");
_ConnectionPtr pConnection("ADODB.Connection" );
  
pConnection-ConnectionString = TableName;
pConnection-Provider = "Microsoft.Jet.OLEDB.4.0";
  
try
{
pConnection-Open(pConnection-ConnectionString, "", "", adModeUnknown);
pRstSchema-QueryInterface(
__uuidof(IADORecordBinding), (LPVOID*)&picRs);
  
pRstSchema = pConnection-OpenSchema(adSchemaTables);//枚举表的名称处理
  
while(!(pRstSchema-EndOfFile))
{
CString strTableType;
  
_bstr_t table_name = pRstSchema-Fields-
GetItem("TABLE_NAME")-Value;//获取表的名称
  
_bstr_t table_type = pRstSchema-Fields-
GetItem("TABLE_TYPE")-Value;//获取表的类型
  
strTableType.Format("%s",(LPCSTR) table_type);
  
if(!lstrcmp(strTableType,_T("TABLE")))
{
m_strList.AddString((LPCSTR) table_name);//添加表的名称
}
  
pRstSchema-MoveNext();
}
// 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);
}
CoUninitialize();
}
  
void PrintProviderError(_ConnectionPtr pConnection)
{
ErrorPtr pErr = NULL;
  
if( (pConnection-Errors-Count) 0)
{
long nCount = pConnection-Errors-Count;
// Collection ranges from 0 to nCount -1.
for(long i = 0;i nCount;i++)
{
pErr = pConnection-Errors-GetItem(i);
CString strError;
strError.Format("Error number: %xt%s", pErr-Number, pErr-Description);
AfxMessageBox(strError);
}
}
}
  
void PrintComError(_com_error &e)
{
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
  
// Print COM errors.
CString strError;
strError.Format("Error number: Description = %stCode meaning = %s",(LPCSTR) bstrDescription, e.ErrorMessage());
AfxMessageBox(strError);
}

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/bianchengyuyan/)

  调用方法:

CString strFileName;
TCHAR FileName[MAX_PATH];
TCHAR bigBuff[2048] = _T(""); // maximum common dialog buffer size
TCHAR szFilter[] = _T("Text Files (*.mdb)|*.mdb|All Files (*.*)|*.*
");
CFileDialog dlg(TRUE, NULL, NULL,
OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT, szFilter);
  
// Modify OPENFILENAME members directly to point to bigBuff
dlg.m_ofn.lpstrFile = bigBuff;
dlg.m_ofn.nMaxFile = sizeof(bigBuff);
  
if(IDOK == dlg.DoModal() )
{
strFileName = dlg.GetPathName();
lstrcpy(FileName,strFileName);
OpenSchemaX(FileName);
}

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/bianchengyuyan/)

来源:https://www.tulaoshi.com/n/20160219/1610448.html

延伸阅读
由于不同版本的ACCESS数据库的数据结构不同,为了用不同版本的ACCESS建立的数据库在其它版本的ACCESS中,就需要将不同版本之间的数据库文件进行转化。 首先我们讲讲将旧版本的数据库转换到“Access2000”所能接收的数据库版本。单击工具栏上的“打开”按钮,选择旧的“数据库”文件, 然后单击“打开”。 单击“选项...
Oracle 9i中提供强大的迁移功能,可以从多种数据库向Oracle迁移数据。Oracle新发行的迁移工具提供了从Access 2000向Oracle 92010迁移的简便易行的解决方案,该方案克服了中文乱码问题和字符串被截断的问题,如下就是从Access 2000向Oracle 92010迁移的全过程。 一、下载最新版本的OMWB(Oracle Migration Workbench) 并安装到下载Oracle ...
Deleting all data from an Access database Sometimes it may be necessary to delete all the data in a database while retaining the table structure. If done manually, this job can quickly become tedious. If your database has many tables, the following code will clear all the data in a hurry. Dim ctr As Container, d...
#include  "utilcls.h"   void  CompactDatabase(String  f1,String  psw1,  String  f2,String  psw2)     {            String  Provider1="...
在Office家族成员中,人们对于Access 2000的了解,往往只局限在它的操作界面中,对于数据库管理的功能仍只是停留在建立表、数据输入、使用窗体向导、报表向导、数据访问页向导等一些简单的应用上。其实Access 2000的功能十分强大,且超乎你的想像。它是微软自公布Access以来功能最全面、与Windows和Internet结合最紧密的数据库软件,是一个...

经验教程

181

收藏

24
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部