🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #20256

Re: importing foxpro data

#20256
From: Ben Dupre
Date: Thu, 01 Aug 2002 17:52
66 lines
3094 bytes
First things first. You have to create a connection object: 

Dim DB as New ADODB.Connection 

Use the open method: 

DB.Open "Connection String" 

Your connection string (this might work for FoxPro, but I have no database to test it on): 

"Provider=MSDASQL; Data Source=C:\path\to\your\file" 

Next, get a recordset: 

Dim RS as New ADODB.Recordset 

Use the open method: 

RS.Open "SQL statement", ActiveConnection, CursorType, LockType, Options 

Your SQL statement: 

"SELECT Field1, Field2, Field3 FROM Table1 WHERE Field1=some value" 

Note: The field names must be enclosed in brackets [] if they contain spaces or odd characters. The WHERE clause is only necessary if you want to get records that match a certain criteria. 

Your connection: DB 

CursorType: default is adOpenForwardOnly, use adOpenStatic. 

RecordLock: default is adLockReadOnly, use adLockPessimistic if you want to change any records. 

Options: Not really sure. It works for me if I just omit. 

Next you want to navigate through your recordset. The recordset object represents one row of a table at a time. Several methods are available for navigation. 

RS.MoveFirst 
RS.MoveLast 
RS.MoveNext 
RS.MovePrevious 

If you navigate through the recordset using a Do loop, you need to check for EOF or BOF to know when you've reached the last or first record. 

Do While Not RS.EOF 
��DeBug.Print RS.Field1.Value 
��DeBug.Print RS.Field2.Value 
��DeBug.Print RS.Field3.Value 
��RS.MoveNext 
Loop 

You might also want to use a For Next loop.  If so, you can use the RecordCount property: 

Dim i as integer 

For i=1 to RS.RecordCount 
��DeBug.Print RS.Field1.Value 
��DeBug.Print RS.Field2.Value 
��DeBug.Print RS.Field3.Value 
��RS.MoveNext 
Next 

For more information, do a search on ADO in your visual studio help. As I said earlier, it is tricky business to make sure the help you're reading applies to the object model you're trying to use. There is DAO, ADO, and several others. The examples I showed above use an ADO connection and an ADO recordset. Although I've not worked with a FoxPro database, the concepts are basically the same for Access. 

Good Luck and don't get discouraged.  It is possible, but usually you have to try a few things before you figure out the right way. 

Ben
Technical Details
Message-ID: <ef9ea8e.4@WebX.aaQKaf7vad4>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-04!supernews.com!iad-peer.news.verio.net!news.verio.net!news.maxwell.syr.edu!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!WebX
References: <ef9ea8e.-1@WebX.aaQKaf7vad4>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: f939a,5850bb65216741b8
X-Google-Attributes: gidf939a,public
X-Google-ArrivalTime: 2002-08-01 11:11:10 PST
From: "Ben Dupre" <bdupre@sauer-danfoss.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-04!supernews.com!iad-peer.news.verio.net!news.verio.net!news.maxwell.syr.edu!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!WebX
Newsgroups: adobe.scripting.indesign
Subject: Re: importing foxpro data
Message-ID: <ef9ea8e.4@WebX.aaQKaf7vad4>
Date: Thu, 1 Aug 2002 10:52:18 -0700
References: <ef9ea8e.-1@WebX.aaQKaf7vad4>
Lines: 81
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit