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);
}(出处:风闪网路学院)
数据挖掘工具