ADO Example TextFile: Difference between revisions

From AutoIt Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
The following example
* Reads all records of a text file and displays all fields for each record
* The fields in the file are delimited by a comma
* The file has no header row
<syntaxhighlight lang="autoit">
<syntaxhighlight lang="autoit">
;------------------------------------------------------------------------
; ADO_Example_TextFile
; Read all records of a text file and display all fields for each record.
; The fields are delimited by a comma. The file has no header row
;------------------------------------------------------------------------
Global $oADOConnection = ObjCreate("ADODB.Connection") ; Create a connection object
Global $oADOConnection = ObjCreate("ADODB.Connection") ; Create a connection object
Global $oADORecordset = ObjCreate("ADODB.Recordset") ; Create a recordset object
Global $oADORecordset = ObjCreate("ADODB.Recordset") ; Create a recordset object

Revision as of 22:19, 4 January 2014

The following example

  • Reads all records of a text file and displays all fields for each record
  • The fields in the file are delimited by a comma
  • The file has no header row
Global $oADOConnection = ObjCreate("ADODB.Connection") ; Create a connection object
Global $oADORecordset = ObjCreate("ADODB.Recordset") ; Create a recordset object
Global $sADOConnectionString = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' & @ScriptDir & ';Extended Properties="Text;HDR=NO;FMT=Delimited(,)"'
$oADOConnection.Open($sADOConnectionString) ; Open the connection
Global $sADOSQL = "Select * From " & "ADO_Example_TextFile.txt" ; Select all records and all fields
$oADORecordset.Open($sADOSQL, $oADOConnection) ; Issue the SQL query
With $oADORecordset
    While Not .EOF ; repeat until End-Of-File (EOF) is reached
        ConsoleWrite(.Fields(0).Value & "|" & .Fields(1).Value & "|" & .Fields(2).Value & "|" & .Fields(3).Value & @CR)
        .MoveNext ; Move To the Next record
    WEnd
EndWith
$oADORecordset.Close ; Close the recordset
$oADORecordset = 0 ; Release the connection object
$oADOConnection.Close ; Close the connection
$oADOConnection = 0 ; Release the connection object