Read the database with C + +, there are 2 ideas, one is to use ODBC driver to write the program, the second is to open any of the file stream of DBF, and then in accordance with the format of DBF published the standard to write their own reading function. The latter posted on the Internet format specification, CSDN Jar also someone said that wrote, villain No, a few days, with the former to fix the problem.
I wrote the MFC program, but since it is to write a log, there is no need to make so complex, the core of the part of it, not difficult. Need the program can give me email. Before running the program, remember to install Odbcvfp.msi and register well msado15.dll. These details will directly affect your results, I have been here for a long time.
Talk less, cut to the chase.
1, connect VFP database (in fact, is to develop a dbf, and then open)
:: CoInitialize (NULL);
Try
{
:: HRESULT hr=m_pconnection.createinstance (__uuidof (Connection));
if (SUCCEEDED (HR))
{
CString strpath;
TCHAR Szcurrentdir[max_path];
:: GetCurrentDirectory (Max_path,szcurrentdir);
Strpath.format (_t ("%s"), Szcurrentdir);
_bstr_t strconnect =_t ("Driver={microsoft FoxPro VFP Driver (*.dbf)};sourcedb=c://temp;sourcetype=dbf;exclusive=no;" Backgroundfetch=yes;collate=machine ");
M_pconnection->open (StrConnect, "", "", adModeUnknown);
}
}
catch (_com_error ex)
{
AfxMessageBox (ex. Description ());
}
2. Read the data
if (FAILED (M_precordset.createinstance (__uuidof (Recordset)))
{
Return
}
Try
{
M_precordset->open ("Your own SQL statement", (idispatch*) m_pconnection,adopendynamic,adlockoptimistic,adcmdtext);
while (!m_precordset->adoeof)
{
Var=m_precordset->fields->getitem ("XXXX (the column name in the SQL statement just now)")->value;
if (var.vt!=vt_null)
{
Yyyy= (char*) _bstr_t (Var);//Get a value and save it to a CString variable
}
M_precordset->movenext ()//move to next record
}//end while
}//end try
catch (_com_error ex)
{
AfxMessageBox (ex. Description ());
}
Beyond C + + original articles, reproduced please indicate the source and retain the original link
This article link: http://www.beyondc.cn/using-c-read-the-vfp-database.html