ADO Example TextFile: Difference between revisions
Jump to navigation
Jump to search
(Created page with "ADO_ConnectionString_TextFile") |
No edit summary |
||
Line 1: | Line 1: | ||
<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 $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 | |||
</syntaxhighlight> |
Revision as of 22:17, 4 January 2014
;------------------------------------------------------------------------
; 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 $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