首页 | CG软件 | CG信息 | CG教程 | 三维作品 | 设计理论 | CG加油站 | 设计鉴赏 | 社区图库 | Flash | 专题 | 顶客 | 论坛 | 博客 | 导航 | 下载 | 高级搜索
RSS
热门: 3D Total  RPC  Evermotion  效果图  创意  装修  优秀作品  Vray  艺术  欣赏

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

来源:不详 作者:佚名 时间:2007-07-05 点击:
名称   数据库   获取   Access  

如何获取Access2000中所有表的名称,以下是实现功能的代码:

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

}

调用方法:

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

}

本文地址:http://www.cg3000.com/html/cgTutorials/Website/SQL/20070705/huoquAccess2000shujukuzhongsuoyoubiaodemingchen_17034.shtml
上一篇:在Linux上安装postgresql的全过程
下一篇:利用最基本的SQL注入渗透BBSXP官方网站的台后管理
关键字:迅雷 快车 Baidu 获取 Access 数据库 名称
最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
注册
图腾CG联盟免责声明:本网站转载纯粹出于为网民传递更多信息之目的,无任何商业目的。如本网站转载稿件涉及版权等问题,请作者速来函admincg3000@163.com联系,在此,我们首先向您表示诚挚的歉意,并将尽快予以改正。本网站上发表的内容只代表作者本人之观点,本网站只出于传递更多信息之目的,并不意味着赞同其观点或证实其内容的真实性。
赞助广告