Using C + + to read VFP database __ Database

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.