ODBC issue with VFP 9

You cannot use ODBC with Visual FoxPro 9.0. Instead you have to use ADO (OLEDB). Unlike ODBC which gives a result set normally as a cursor, ADO gives the result set as an object (Dataset in .Net).

I tried this from within VFP (assuming a database named prodata and tables named syccomp, arcust99 in that database) and it worked.
Here is what I did:

oConn = CREATEOBJECT("ADODB.Connection")
oConn.ConnectionString = "provider=vfpoledb.1;;
data source=.\prodata.dbc"
oConn.Open
? oconn.Execute("Select * from syccomp")
lo =oconn.Execute("Select * from syccomp")
? lo.Fields[1].value
ln = 1

lo =oconn.Execute("Select * from arcust99", @ln)
? ln
? lo.Fields[1].value
? lo.Fields[0].value

You can use "DIM" to create the object in VB and use the Execute to get to the VFP data.

No comments: