Both are all use of Adox's Catalog, just a little difference when introducing, using the namespace:
1
Need to use ADO and ADOX, introduce methods:
#import "c: / program files / compon files / system / ado / msado15.dll" Rename ("EOF", "AdoEOF")
#import "c: / program files / compon files / system / ado / msadox.dll"
Because the Namespace of the two libraries is different, the first is adoDB, the second is Adox, pay attention to the NO_NAMESPACE that is usually added above the first line!
In the previous couple, add adoDB :: in front of the variable in the namespace to which ADO
When using the namespace of the name of the ADOX, when the function is added, add adox ::
HRESULT HR = S_OK;
HR = :: Coinitialize (NULL);
En (ac))
{
HRESULT HR = S_OK;
// define adox object Pointers.
// Initialize Pointers on Define.
// These is in the adox :: namespace.
Adox :: _ CatalogPtr M_PCATALOG = NULL;
// set activeConnection of catalog to this string
_BSTR_T STRCNN ("provider = microsoft.jet.Oledb.4.0; data source = c: //new.mdb");
Try
{
M_PCATALOG.CREATEINSTANCE (__ uuidof (adox :: catalog);
M_PCATALOG-> CREATE (STRCNN);
}
Catch (_COM_ERROR & E)
{
// Notify the user of errors if any.
AfxMessageBox (E.ErrorMessage ());
}
}
reference:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/admthcreatexvc.asp
2
Some differences in this way
First on the header file. H Add:
#import "c: / program files / compon files / system / ado / msadox.dll" rename_namespace ("adox")
#import "c: / program files / compon files / system / ado / msado15.dll" /
Rename_namespace ("ADO") Rename ("EOF", "Endoffile")
#pragma Warning (Disable: 4146) Using Namespace ADO;
Then in the implementation file .CPP:
Using Namespace Adox;
_Catalogptr m_pcatalog;
M_PCATALOG.CREATEINSTANCE (__ uuidof (catalog));
Try
{
//m_pcatalog.createInstance (__uuidof(adox ::catalog));
M_PCATALOG-> CREATE (STRCNN);
}
Catch (_COM_ERROR & E) {
// Notify the user of errors if any.
AfxMessageBox (E.ErrorMessage ());
Return False;
}
Using namespace ado; // If the code is used, the ADO is used to add this sentence.
Personally feel that the second use is convenient.