Use ADO in VC
Import ADO Type Library #pragma Warning (Disable: 4146)
#import "C: / Program files / compon files / system / ado / msado15.dll" no_namespace rename ("EOF", "AdoEOF")
#pragma Warning (Default: 4146) Note: This sentence is compiled in the latest SDK! (???) Add automation support to add if (! Afxoleinit ()) in CMYApp :: InitInstance ()
Return False; Take CaboutDLG as an example, place a listbox control therein, declare to M_LIST declaration in CaboutDLG _RecordSetPtr M_PRecordset;
_ConnectionPtr M_PCONNECTION; establish connection in OnInitDialog () TRY {
M_PConnection.createInstance (__ uuidof (connene));
M_PConnection.Open ("provider = microsoft.jet.Oledb.4.0; data source = E: //gcl6//data/test.mdb;",
"", ", - 1); // Mok space in" = "!
Catch (...)
{
AfxMessageBox ("Database connection failed!");
} Open inquiry, access data _variant thevalue;
M_PRecordSet.createInstance (__ uuidof (recordset);
M_List.resetContent ();
Try
{
m_precordset-> Open ("Select * from Property", // Note: M_PRecordset will be added after the M_PRecordset.
m_pconnection.getInterfacePtr (),
AdoPENDYNAMIC,
AdlockOptimistic,
AdcmdText
);
While (! m_precordset-> adoEof)
{
Thevalue = m_precordset-> getCollect ("caption");
IF (Thevalue.Vt! = VT_NULL)
M_List.Addstring ((char *) _ bstr_t (thevalue));
M_PRecordset -> MoveNext ();
}
M_PRecordset -> Close ();
}
Catch (...)
{
AfxMessageBox ("Error!");
} Access domain FieldPRT Pfield;
For (int i = 0; i
{
Pfield = m_precordset-> fields-> GetItem (i)));
} (char *) Pfield-> Name is domain name. Pfield-> Type is the data type Pfield-> Precision is accurate note: numeric type and currency type precision less than 255, and the remaining types are 255. Enumerate all tables / query m_precordset = m_pconnetion-> OpenSchema (AdsChematable);
While (! m_precordset-> adoEof) {
CHAR PTYPE [40];
STRCPY (ptype, (char *) _ bstr_t (m_precordset-> getCollect ("Table_Type"))))
IF (! strcmp (ptype, "table") // "view" corresponds to the query
m_precordset -> getCollect ("Table_name"); // Get the table name (need to be transformed)
}