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

出处:Examlink收集整理 作者:马化鸦 日期:2007年06月08日 16时39分
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();

  }    

最后更新时间:2008-05-28 11:52:51
文章评论
共有 0 位网友发表了评论
用户名: 新注册) 密码: 匿名评论 [查看所有评论]

评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
您可以用以下几种方式找到此文章

考试全流程

栏目文章精选