VFP OleDB [examples]

You can use OleDB with the VFP OleDB driver if you need to work directly with existing VFP data. This works in desktop and cloud Apps.

OleDB is a COM technology so it is Windows-only. An ODBC driver for VFP can be downloaded from https://www.devart.com/odbc/

private oConn, oRS, m_count
oConn = createobject("ADODB.Connection")
oRS = createobject("ADODB.Recordset")
lcConnString = "Provider=vfpoledb;Data Source=C:\Temp\Northwind\northwind.dbc"
oconn.ConnectionString = lcConnString
oRS.Open("select * from customers where customerid='BOTTM'", oconn)
m_count = oRs.fields.count
// display the first record selected
for i=0 to m_count
        ? "Name=" + oRS.Fields.item(i).Name + ",value=" + etos(oRS.Fields.item(i).Value)
        // ignore error from Memo

Notice how you must use the item() method on the Fields property as this is exposed only as a property not a method.

The output produced is as follows:

Name=companyname,value=Bottom-Dollar Markets                   
Name=contactname,value=Elizabeth Lincoln             
Name=contacttitle,value=Accounting Manager            
Name=address,value=23 Tsawassen Blvd.                                          
Name=postalcode,value=T2F 8M4   
Name=phone,value=(604) 555-4729          
Name=fax,value=(604) 555-3745  

Note: There is a known issue with retrieving memo fields using the VFP OleDB driver which is why TRY/CATCH to ignore the error.



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.