袁绍伦
路人甲
路人甲
  • 注册日期2003-08-08
  • 发帖数654
  • QQ164646905
  • 铜币1336枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:1311回复:0

C++ Example of an ADO Dataset

楼主#
更多 发布于:2003-09-03 21:36

#import "C:\program files\common files\system\ado\msado15.dll" \
    rename ("EOF", "adoEOF")
 :
 :
 :
/*
 * This must be here to ensure that COM is always initialized.
 * We could alternately put the CoInitialize and CoUninitialize
 * calls in InitInstance and ExitInstance of our application
 * class.
 */
static struct InitOle {
 InitOle()  { ::CoInitialize(NULL); }
 ~InitOle() { ::CoUninitialize();   }
} _init_InitOle_;

inline void TESTHR(HRESULT x) {if FAILED(x) _com_issue_error(x);};

 :
 :
 :
void CMapXView::OnADODSet()
{
 // Note: instead of having all these ADODB:: qualifiers,
 // we could have just put "using namespace ADODB;" at the top
 // of this file.
 ADODB::_RecordsetPtr rsPtr;
 HRESULT hr;
 COptionalVariant optVt;
 CMapXDataset ds;
 COleVariant rsVt;

 // Create a new Recordset object
 TESTHR(hr = rsPtr.CreateInstance(__uuidof(ADODB::Recordset)));

 // Open the ADO recordset to import the USA data.
 // Change the "Data Source=" line if MapX was installed in a
 // different location.

 hr = rsPtr->Open("Select * from USA", "Provider=Microsoft.Jet.OLEDB.3.51;"
 "Data Source=C:\\Program Files\\MapInfo\MapX 5.0\\Data\\MapStats.mdb",
 ADODB::adOpenStatic, ADODB::adLockReadOnly, ADODB::adCmdText);

 // Make sure the Open() succeeded.
 TESTHR(hr);

 // Make the rsVt variant point to our recordset object.
 rsVt.vt = VT_DISPATCH;
 rsVt.pdispVal = rsPtr;
 rsVt.pdispVal->AddRef();

 try {
  // Add a dataset to the map and create a simple theme
  //from it.

  ds = m_ctrlMapX.GetDatasets().Add(miDataSetADO, rsVt, COleVariant("ADOSet"), optVt,
   optVt, COleVariant("USA"), optVt, optVt);

  ds.GetThemes().Add(miThemeRanged, "TOTPOP");
 } catch(COleDispatchException* e) {
  e->ReportError();
  e->Delete();
 } catch(COleException* e) {
  e->ReportError();
  e->Delete();
 }
}
喜欢0 评分0
愿意和大家交朋友! QQ:47559983 MSN:shaolun_yuan@hotmail.com eMail:shaolun-yuan@163.com
游客

返回顶部