Home > Archive > Visual FoxPro SQL Queries > January 2006 > Simple ADO example?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Simple ADO example?
Tom Edelbrok

2006-01-19, 8:25 pm

I don't use VFP very often but am quite versed with VB6 and VB.NET using ADO
and ADO.NET. Can anyone post me a simple example of a VFP program that opens
a connection to a SQL Server and reads a RecordSet (or some such object)
into VFP, then writes data to a SQL Table?

I've been in the VFP help (I believe we have VFP 8.0 or 8.1) and set up a
form-based CursorAdaptor that reads my PostgreSQL data nicely, but I don't
actually want the connection embedded into a form. Instead, like in VB, I
want to programmatically read and write data using objects (without having
to depend on forms).

Thanks for help,

Tom


Alex Feldstein

2006-01-19, 8:25 pm

On Thu, 19 Jan 2006 21:09:19 GMT, "Tom Edelbrok"
<anonymous@anonymous.com> wrote:

>I don't use VFP very often but am quite versed with VB6 and VB.NET using ADO
>and ADO.NET. Can anyone post me a simple example of a VFP program that opens
>a connection to a SQL Server and reads a RecordSet (or some such object)
>into VFP, then writes data to a SQL Table?
>
>I've been in the VFP help (I believe we have VFP 8.0 or 8.1) and set up a
>form-based CursorAdaptor that reads my PostgreSQL data nicely, but I don't
>actually want the connection embedded into a form. Instead, like in VB, I
>want to programmatically read and write data using objects (without having
>to depend on forms).


http://fox.wikis.com/wc.dll?Wiki~CategoryADO
http://fox.wikis.com/wc.dll?Wiki~UsingADO
http://www.eps-software.com/knowled...dorecordset.htm
http://fox.wikis.com/wc.dll?Wiki~OleDB
http://fox.wikis.com/wc.dll? Wiki~V...Provi
der


--- ADO Jumpstart for Visual FoxPro Developers ---
http://msdn.microsoft.com/library/techart/ADOJump.htm
http://msdn.microsoft.com/library/d...tml/adojump.asp


For ADO.NET, see in UT:
http://www.universalthread.com
Using ADO.NET to create databases Thread #762598
OLEDB and DBC Events and .NET Client Q Thread #751201
AddNew in ADO.NET Thread #673112
OLEDB Provider and ADO.NET Thread #628467
http://www.gotdotnet.com/team/vfp/



Alex Feldstein
____________________
____________
Microsoft Visual FoxPro MVP
Please respond in the public groups so that everybody
can benefit from the exchange.
Favor de responder en los foros públicos asi todos se benefician.
(address munged with ROT-13)

Blog: http://www.bloglines.com/blog/AlexFeldstein
Website: http://feldstein.net
Lee Mitchell

2006-01-19, 8:25 pm

Hi Tom:

This may not be exactly what you need, but see if the code in this article
helps you:

272338 How to use Visual FoxPro 6.0 and later versions and the ADO Stream
object to handle Binary Large Object (BLOB) data
http://support.microsoft.com/defaul...kb;EN-US;272338

I hope this helps.

This posting is provided "AS IS" with no warranties, and confers no rights.

Sincerely,
Microsoft FoxPro Technical Support
Lee Mitchell

*-- VFP9 HAS ARRIVED!! --*
Read about all the new features of VFP9 here:
http://msdn.microsoft.com/vfoxpro/

*--Purchase VFP 9.0 here:
http://www.microsoft.com/PRODUCTS/i...cid=54787e64-52
69-4500-8bf2-3f06689f4ab3&type=ovr

Keep an eye on the product lifecycle for Visual FoxPro here:
http://support.microsoft.com/gp/lifeselectindex
- VFP5 Mainstream Support retired June 30th, 2003
- VFP6 Mainstream Support retired Sept. 30th, 2003

>I don't use VFP very often but am quite versed with VB6 and VB.NET using

ADO
>and ADO.NET. Can anyone post me a simple example of a VFP program that

opens

>a connection to a SQL Server and reads a RecordSet (or some such object)
>into VFP, then writes data to a SQL Table?


>I've been in the VFP help (I believe we have VFP 8.0 or 8.1) and set up a
>form-based CursorAdaptor that reads my PostgreSQL data nicely, but I don't
>actually want the connection embedded into a form. Instead, like in VB, I
>want to programmatically read and write data using objects (without having
>to depend on forms).


>Thanks for help,


>Tom



Cindy Winegarden

2006-01-21, 8:24 pm

Hi Tom,

First off, you can create a cursor adapter in code and work with it in code.
You can use SCAN...ENDSCAN to iterate through the source CursorAdapter,
do whatever you want to the record and then insert it into the destination
CursorAdapter

To work with the CursorAdapter without a form, create a new class library,
add a
class based on CursorAdapter. When the GUI interface to the class comes up
you can right-click on it and choose Builder... to easily set all the
properties. When you want to work with this CursorAdapter you can use code
like myCursorAdapterInsta
nce =CreateObject(myCurs
orAdapter) . After you
instantiate your CursorAdapter you can easily change properties such as the
connection string as you like.

I created a Cursor Adapter class called caTest In the Test.vcx class
library. As above I used the builder. I used the Class Browser to look at
the code. Besides using a class library you can create the whole thing in
code as below. (Sorry it's ugly when the lines wrap.)

*-- ---------------------------------------------------------
********************
********************
**********
*-- Class: catest (d:\visual foxpro\test.vcx)
*-- ParentClass: cursoradapter
*-- BaseClass: cursoradapter
*-- Time Stamp: 01/21/06 04:38:01 PM
*
DEFINE CLASS catest AS cursoradapter


Tag = & #91;'Provider=VFPOLE
DB.1;Data Source=C:\Program Files\Microsoft Visual
FoxPro 9\Samples\Northwind\
Northwind.dbc;Password="";Collating
Sequence=MACHINE;']
Height = 22
Width = 23
SelectCmd = "Select Customers.* from Customers"
CursorSchema = "CUSTOMERID C(5), COMPANYNAME C(40), CONTACTNAME C(30),
CONTACTTITLE C(30), ADDRESS C(60), CITY C(15), REGION C(15), POSTALCODE
C(10), COUNTRY C(15), PHONE C(24), FAX C(24)"
Alias = "cursor1"
DataSourceType = "ADO"
Flags = 0
KeyFieldList = "CUSTOMERID"
Tables = "Customers"
UpdatableFieldList = "COMPANYNAME, CONTACTNAME, CONTACTTITLE, ADDRESS,
CITY, REGION, POSTALCODE, COUNTRY, PHONE, FAX"
UpdateNameList = "CUSTOMERID Customers.CUSTOMERID, COMPANYNAME
Customers.COMPANYNAME, CONTACTNAME Customers.CONTACTNAME, CONTACTTITLE
Customers.CONTACTTITLE, ADDRESS Customers.ADDRESS, CITY Customers.CITY,
REGION Customers.REGION, POSTALCODE Customers.POSTALCODE, COUNTRY
Customers.COUNTRY, PHONE Customers.PHONE, FAX Customers.FAX"
UseCursorSchema = .T.
Name = "catest"


PROCEDURE Init
*** Setup code: DO NOT REMOVE
local llReturn
do case
case not pemstatus(This, '__VFPSetup', 5)
This. AddProperty('__VFPSe
tup', 0)
case This.__VFPSetup = 1
This.__VFPSetup = 2
case This.__VFPSetup = 2
This.__VFPSetup = 0
return
endcase
set multilocks on
llReturn = dodefault()
*** End of Setup code: DO NOT REMOVE
*** Select connection code: DO NOT REMOVE

local loConnDataSource
loConnDataSource = createobject('ADODB.Connection')
***<DataSource>
loConnDataSource.ConnectionString = & #91;Provider=VFPOLED
B.1;Data
Source=C:\Program Files\Microsoft Visual FoxPro 9] + ;
& #91;\Samples\Northwi
nd\Northwind.dbc;Password="";Collating
Sequence=MACHINE;]
***</DataSource>
loConnDataSource.Open()
This.DataSource = createobject('ADODB.RecordSet')
This.DataSource.CursorLocation = 3 && adUseClient
This.DataSource.LockType = 3 && adLockOptimistic
This.DataSource.ActiveConnection = loConnDataSource
*** End of Select connection code: DO NOT REMOVE

*** Setup code: DO NOT REMOVE
if This.__VFPSetup = 1
This.__VFPSetup = 2
endif
return llReturn
*** End of Setup code: DO NOT REMOVE
ENDPROC


PROCEDURE AutoOpen
*** Setup code: DO NOT REMOVE
if not pemstatus(This, '__VFPSetup', 5)
This. AddProperty('__VFPSe
tup', 1)
This.Init()
endif
*** End of Setup code: DO NOT REMOVE
ENDPROC


ENDDEFINE
*
*-- EndDefine: catest
********************
********************
**********

*-- ---------------------------------------------------------

--
Cindy Winegarden MCSD, Microsoft Visual FoxPro MVP
cindy_winegarden@msn
.com www.cindywinegarden.com


"Tom Edelbrok" <anonymous@anonymous.com> wrote in message
news:3eTzf.80706$m05.24761@clgrps12...
>I don't use VFP very often but am quite versed with VB6 and VB.NET using
>ADO and ADO.NET. Can anyone post me a simple example of a VFP program that
>opens a connection to a SQL Server and reads a RecordSet (or some such
>object) into VFP, then writes data to a SQL Table?
>
> I've been in the VFP help (I believe we have VFP 8.0 or 8.1) and set up a
> form-based CursorAdaptor that reads my PostgreSQL data nicely, but I don't
> actually want the connection embedded into a form. Instead, like in VB, I
> want to programmatically read and write data using objects (without having
> to depend on forms).
>
> Thanks for help,
>
> Tom
>




Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com