获取ACCESS2000数据库中所有表的名称建站知识
导读:1建站知识void OpenSchemaX(TCHAR *TableName) { HRESULT hr = S_OK; ::CoInitialize(NULL); //个业网站建设公司seo网站关键词优化。
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 pErrseo网站关键词优化 = 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: %x\t%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 = %s\tCode meaning = %s",(LPCSTR) bstrDescription, e.ErrorMessage());
AfxMessageBox(strError);
}
调用方法:
CString strFileName;
TCHAR FileName[MAX_PATH];
声明: 本文由我的SEOUC技术文章主页发布于:2023-05-23 ,文章获取ACCESS2000数据库中所有表的名称建站知识主要讲述数据库中,名称,获取ACCESS2000数据库中所有表的名网站建设源码以及服务器配置搭建相关技术文章。转载请保留链接: https://www.seouc.com/article/web_6106.html