数据库是变动的。也就是说我用_ConnectonPtr连接了一个数据库。如何得知这个数据库的Table和table的名字。
解决方案 »
- 一个子线程中调用dll函数的问题
- 请教大家,如何从一个OCX中遍历出它的所有属性,就象VC的设计界面能够看到控件的属性,谢谢大家!!!!
- 嵌入式软件有用VC开发的吗
- 深入浅出MFC第一版跟第二版区别大吗?
- 工具栏的问题,怎么一点自己设置的图标就死机?
- Microsoft Speech SDK 5.1软件包在哪里找?
- 刚买了个音视频采集卡,想自己做程式控制,主要是录音方面和音频处理,求帮助
- 各位有考过MCSD(VB)的吗,介绍介绍经验!!!
- 在控制“最近打开文档”菜单时碰到的一个问题
- 请教各位高手,我在全局主线程中怎样才能禁止DLG类中的一个按钮状态?
- 关于ADO的问题
- MFC中那么多Style, 而且Create的时候,又经常要写好多个,大家都是怎么记住的啊?
#import "c:\Program Files\Common Files\system\ado\msadox.dll" \
no_namespace
#import "c:\Program Files\Common Files\system\ado\msado15.dll"#include "iostream.h"
#include "stdio.h"
#include "conio.h"//Function declarations
inline void TESTHR(HRESULT x) {if FAILED(x) _com_issue_error(x);};
void CloseConnectionByNothingX(void);
void CloseConnectionX(void);//////////////////////////////////////////////////////////
// //
// Main Function //
// //
//////////////////////////////////////////////////////////
void main()
{
if(FAILED(::CoInitialize(NULL)))
return; CloseConnectionByNothingX(); CloseConnectionX(); ::CoUninitialize();
}//////////////////////////////////////////////////////////
// //
// CloseConnectionByNothingX Function //
// //
//////////////////////////////////////////////////////////
void CloseConnectionByNothingX(void)
{
HRESULT hr = S_OK; // Define ADOX object pointers.
// Initialize pointers on define.
// These are in the ADOX:: namespace. _CatalogPtr m_pCatalog = NULL;
_TablePtr m_pTable = NULL; //Define ADODB object pointers
ADODB::_ConnectionPtr m_pCnn = NULL; //Define other variables
_variant_t vIndex = (short) 0; try
{
TESTHR(hr = m_pCnn.CreateInstance(__uuidof(ADODB::Connection))); TESTHR(hr = m_pCatalog.CreateInstance(__uuidof(Catalog)));
m_pCnn->Open("Provider=Microsoft.Jet.OLEDB.4.0;"
"Data Source= c:\\Program Files\\Microsoft Office\\"
"Office\\Samples\\Northwind.mdb;","","",NULL); m_pCatalog->PutActiveConnection(_variant_t((IDispatch *)m_pCnn)); m_pTable = m_pCatalog->Tables->GetItem(vIndex); // Cache m_pTable.Type info
cout << m_pTable->Type << endl; _variant_t vCnn;
vCnn.vt = VT_DISPATCH;
vCnn.pdispVal = NULL;
m_pCatalog->PutActiveConnection(vCnn); // m_pTable is orphaned
cout << m_pTable->Type << endl; // Previous line will succeed if this was cached
cout << m_pTable->Columns->GetItem(vIndex)->DefinedSize << endl;
// Previous line will fail if this info has not been cached
} catch(_com_error &e)
{
// Notify the user of errors if any.
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description()); printf("\n\tSource : %s \n\tdescription : %s \n ",(LPCSTR)bstrSource,(LPCSTR)bstrDescription);
} catch(...)
{
cout << "Error occured in include files...."<< endl;
}
}//////////////////////////////////////////////////////////
// //
// CloseConnectionX Function //
// //
//////////////////////////////////////////////////////////
void CloseConnectionX()
{
HRESULT hr = S_OK; // Define ADOX object pointers.
// Initialize pointers on define.
// These are in the ADOX:: namespace. _CatalogPtr m_pCatalog = NULL;
_TablePtr m_pTable = NULL; //Define ADODB object pointers
ADODB::_ConnectionPtr m_pCnn = NULL; //Define other variables
_variant_t vIndex = (short) 0;
try
{
TESTHR(hr = m_pCnn.CreateInstance(__uuidof(ADODB::Connection)));
m_pCnn->Open("Provider=Microsoft.Jet.OLEDB.4.0;"
"Data Source= c:\\Program Files\\Microsoft Office\\"
"Office\\Samples\\Northwind.mdb;","","",NULL); TESTHR(hr = m_pCatalog.CreateInstance(__uuidof(Catalog)));
m_pCatalog->PutActiveConnection(_variant_t((IDispatch *)m_pCnn)); m_pTable = m_pCatalog->Tables->GetItem(vIndex); // Cache m_pTable.Type info
cout << m_pTable->Type << endl; m_pCnn->Close(); // m_pTable is orphaned
cout << m_pTable->Type << endl; // Previous line will succeed if this was cached
cout << m_pTable->Columns->GetItem(vIndex)->DefinedSize << endl;
// Previous line will fail if this info has not been cached
} catch(_com_error &e)
{
// Notify the user of errors if any.
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description()); printf("\nError\n\tSource : %s \n\tdescription : %s \n ",
(LPCSTR)bstrSource,(LPCSTR)bstrDescription);
} catch(...)
{
cout << "Error occured in include files...."<< endl;
}
}
// EndCloseConnectionCpp
所有用户表
select table_name from user_tables;所有表(包括系统表)
select table_name from all_tables;
谢谢。你的例子是msdn。net中的。我看过了。我的意思不是这样的。
好比你用access打开一个mdb.它会出现一个小窗口。其中就列出了你的表名
(好比说是"test")双击test打开test表。用sql的时候就可以select * from
test.问题是我的程序中用file---open打开一个mdb的时候。如何知道这个表的名字呢(如何知道是"test"or "hand"...."hello word")
2 ZHENG017(风中王子) :
mdb中不行吧