Article ID: 146224
Article Last Modified on 3/14/2005
SET DEFAULT TO home()+"samples\data" USE customer COPY TO customer.csv DELIMITED && Creates comma-delimited Customer file USE
* Start of Program to connect to "FoxPro Text Test" Data Source
LOCAL lcSource, lnConHand, lnSQLRes
* Set initial variable values
STORE 0 TO lnConHand, lnSQLRes
lcSource = "FoxPro Text test" && Text Data Source Name from ODBC Dialog
* Connect to Text Data Source
WAIT Window "Attempting connection ..." NOWAIT
lnConHand = SQLCONNECT(lcSource)
IF lnConHand > 0
WAIT Window ;
"Connected to Text File Driver - Handle:" ;
+ STR(lnConHand,2,0) TIMEOUT 2
ELSE
WAIT Window ;
"Unable to connect to Text File ..." TIMEOUT 2
ENDIF
* Bring data into cursor called CustText
IF lnConHand>0
lnSQLRes=SQLEXEC(lnConHand, "SELECT * FROM Customer.csv","CustText")
BROWSE NOWAIT
lnSQLRes=SQLDISCONNECT(lnConHand) && Remove to leave connection open
ENDIF
* End of program
[customer.csv] ColNameHeader=False Format=CSVDelimited MaxScanRows=25 CharacterSet=OEM Col1=F1 Char Width 254 Col2=F2 Char Width 254 Col3=F3 Char Width 254 Col4=F4 Char Width 254 Col5=F5 Char Width 254 Col6=F6 Char Width 254 Col7=F7 Char Width 254 Col8=F8 Char Width 254 Col9=F9 Char Width 254 Col10=F10 Char Width 254 Col11=F11 Char Width 254 Col12=F12 FloatThe correct column names and field lengths and from the Customer table (obtained with a LIST STRUCTURE command) can be used to modify the Schema.ini file as follows to allow correct column names and widths to appear in Visual FoxPro. These modifications can also be made through the Define Text Format dialog box.
[customer.csv] ColNameHeader=False Format=CSVDelimited MaxScanRows=25 CharacterSet=OEM Col1=CUST_ID Char Width 6 Col2=COMPANY Char Width 40 Col3=CONTACT Char Width 30 Col4=TITLE Char Width 30 Col5=ADDRESS Char Width 60 Col6=CITY Char Width 15 Col7=REGION Char Width 15 Col8=POSTALCODE Char Width 10 Col9=COUNTRY Char Width 15 Col10=PHONE Char Width 24 Col11=FAX Char Width 24 Col12=MAXORDAMT FloatThe Text File driver supports the SQL SELECT and INSERT commands only, not DELETE or UPDATE. This prevents deleting or modifying existing records.
Additional query words: SPT VFoxWin
Keywords: kbhowto kbcode KB146224