To access VFP DBCs use the OLE/DB provider. You can download it here:
<pre>
[
www.microsoft.com]
</pre>
Here is a sample of how to access a a VFP DBF via OLE/DB. I am accessing the DBFs directly but the principle is the same for accessing them via DBCs.
<pre>
// Define some variables for access the DBF via OLE/DB
cn_VFPData is Connection
ds_VFPData is Data Source
l_sQueryString is string
// Fill in items in the Connection
cn_VFPData..User = ""
cn_VFPData..Password = ""
cn_VFPData..Server = "localhost"
cn_VFPData..Database = ""
cn_VFPData..Source = "I:\ProgDir\DataDir"
cn_VFPData..Provider = "VFPOLEDB.1"
cn_VFPData..Access = hOReadWrite
cn_VFPData..ExtendedInfo = ""
// Open the Connection
IF NOT HOpenConnection( cn_VFPData ) THEN
Info(HErrorInfo())
END
// Build the query in a String variable
// -----------------
// Note 1: The variable is enclosed in double quotes so we need to use either
// single quotes or [] brackets to enclose text within the query string
// -----------------
// Note 2: This is VFP SQL here, type it as if you were going to execute it from
// the VFP command window
sQueryString = "SELECT field1, field2, filed3, field4 FROM VFP_DBF WHERE TextField='ABCD' AND NumericField=1234 AND DTOS(DateField) = '20080728'"
IF NOT HExecuteSQLQuery(ds_VFPData, cn_VFPData, hQueryWithoutCorrection, sQueryString) THEN
Info(HErrorInfo())
END
// Set to True to view results via the WinDev BuildBrowsingTable function
IF True THEN
BuildBrowsingTable(TABLE_VFPData, ds_VFPData, taFillTable)
{"TABLE_VFPData._COL4"}..InputMask = "MM/DD/YYYY"
END
// Set to True to step through results and add them to a WinDev Table
IF False THEN
HReadFirst(ds_VFPData)
TableDeleteAll(TABLE_VFPData)
WHILE HOut(ds_VFPData) = False
TableAddLine(TABLE_VFPData, ds_VFPData.field1, ds_VFPData.field2, ds_VFPData.field3, ds_VFPData.field4)
HReadNext(ds_VFPData)
END
END
HCancelDeclaration(ds_VFPData)
HCloseConnections(cn_VFPData)
</pre>
For more information see the following topics in the VFP help file:
How to: Access Visual FoxPro Data in Visual Studio
Language Reference for OLE DB Development
Edited 4 time(s). Last edit at 07/28/2008 07:22PM by David Martin.