阅读:1517回复:0
C++ Example of an ODBC Datasetvoid CMapXView::OnODBC() { CMapXDataset ds; CMapXODBCQueryInfo parm; COleVariant parmVt; try { // Create a new ODBCQueryInfo object parm.CreateDispatch(parm.GetClsid()); parm.SetSqlQuery("select * from USA"); // if the ConnectString is left blank, the user will be // prompted to find a driver and data source. This can // include uid=, pwd=, and dlg= fields. // Change the DBQ= line if MapX was installed in another // location. parm.SetConnectString("ODBC;DRIVER={Microsoft Access Driver (*.mdb)};" "DBQ=C:\\Program Files\\MapInfo\MapX 5.0\\Data\\MapStats.mdb;"); // Rather than providing connection information in the // connect string, a named data source can be created in // the ODBC Data Sources Control Panel and used here. parm.SetDataSource(""); // Set the variant parmVt to point to our ODBCQueryInfo // object. parmVt.vt = VT_DISPATCH; parmVt.pdispVal = parm.m_lpDispatch; parmVt.pdispVal->AddRef(); // Add the Dataset. ds = m_ctrlMapX.GetDatasets().Add(miDataSetODBC, parmVt, "ODBC Dataset"); // Create the default theme on the dataset ds.GetThemes().Add(COptionalVariant(), COptionalVariant(), COptionalVariant()); } catch (COleDispatchException *e) { e->ReportError(); e->Delete(); } catch (COleException *e) { e->ReportError(); e->Delete(); } } |
|
|