Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VFP to ADO to SQL Server
Message
General information
Forum:
Visual FoxPro
Category:
Client/server
Miscellaneous
Thread ID:
00359060
Message ID:
00359456
Views:
7
>I am looking for some sample code showing ADO being used to send data back and forth between VFP and SQL Server.
>
>Thanks v. much in advance!

Following is simplistic code for reading from VFP table and writing to SQL server table:
Local cCnString, oConn, oRS, cSql, cText

oConn = CreateObject("ADODB.connection")
oRS = CreateObject("ADODB.Recordset")  

*-- VFP free table ODBC connection string
cCnString= "Driver=Microsoft Visual FoxPro Driver; " + ;
"SourceType=DBf;SourceDB=c:\test;BackgroundFetch=No;"
oConn.Open(cCnString)

oRS.cursortype = 3 && adOpenStatic
oRS.cursorlocation = 3 && adUseClient
oRS.locktype = 3 && adLockOptimistic
oRS.Open("select * from customer",oConn)

*-- Disconnect cursor and reuse connection object
*-- with SQL Server OLEDB connection string
oRS.ActiveConnection = .null.
Do while oConn.State=1
	oConn.Close
Enddo
cCnString= "Provider=SQLOLEDB.1;"+;
	"Integrated Security=SSPI;"+;
	"Persist Security Info=False;"+;
	"Initial Catalog=mySQLTable;"+;
	"Data Source=mySQLServer"
oConn.Open(cCnString)

*-- Loop through recordset and write to SQL Server
*-- using a sql statement. can be done w/ADO too
cText = "Insert Into customer Values ("
Do While Not oRS.EOF
	cSql = cText + Transform(oRS.Fields("custid").Value) + ","
	cSql = cSql + "'" + oRS.Fields("name").Value + "')"
	oConn.Execute(cSql,,128) && adExecuteNoRecords
	oRS.MoveNext
EndDo

oRS.Close
oConn.Close
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform