Difference between revisions of "Working with OleDB"
From Lianjapedia
Barrymavin (Talk | contribs) (Created page with "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. <code lang="recital"> private oConn, oR...") |
Barrymavin (Talk | contribs) |
||
Line 1: | Line 1: | ||
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. | 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. As opposed to ODBC, which is platform independent; Windows, Linux and macOS. | ||
<code lang="recital"> | <code lang="recital"> |
Revision as of 10:42, 13 December 2017
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. As opposed to ODBC, which is platform independent; Windows, Linux and macOS.
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 oconn.Open() 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 try ? "Name=" + oRS.Fields.item(i).Name + ",value=" + etos(oRS.Fields.item(i).Value) catch // ignore error from Memo endtry endfor
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=customerid,value=BOTTM Name=companyname,value=Bottom-Dollar Markets Name=contactname,value=Elizabeth Lincoln Name=contacttitle,value=Accounting Manager Name=address,value=23 Tsawassen Blvd. Name=city,value=Tsawassen Name=region,value=BC Name=postalcode,value=T2F 8M4 Name=country,value=Canada 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.