ADO Example TextFile: Difference between revisions

From AutoIt Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 21: Line 21:
$oADOConnection = 0 ; Release the connection object
$oADOConnection = 0 ; Release the connection object
</syntaxhighlight>
</syntaxhighlight>
Input file "ADO_Example_TextFile.txt":
11,12,13,14
21,22,23,24

Revision as of 22:33, 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

Input file "ADO_Example_TextFile.txt":

11,12,13,14
21,22,23,24