Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista Tutorial - Using ADO to read a text file

Reply
 
Old 11-08-2006   #1 (permalink)
Marco Shaw
Guest


 
 

Using ADO to read a text file

Trying the following PSH code:

$adOpenStatic = 3
$adLockOptimistic = 3

$objConnection = New-Object -comobject ADODB.Connection
$objRecordset = New-Object -comobject ADODB.Recordset

$objConnection.Open("Provider = Microsoft.Jet.OLEDB.4.0; Data Source =
c:\test.2; Extended Properties = text; HDR=YES; FMT=Delimited")
$objRecordset.Open("Select * from test.2",
$objConnection,$adOpenStatic,$adLockOptimistic)

$objRecordset.MoveFirst()

do {$objRecordset.Fields.Item("Name").Value; $objRecordset.MoveNext()} until
($objRecordset.EOF -eq $True)

$objRecordset.Close()
$objConnection.Close()

PSH errs out here:
PS C:\> $objConnection.Open("Provider = Microsoft.Jet.OLEDB.4.0; Data Source
= c:\test.2; Extended Properties = text; HDR=YES; FMT=Delimited")
Exception calling "Open" with "4" argument(s): "Could not find installable
ISAM."
At line:1 char:20
+ $objConnection.Open( <<<< "Provider = Microsoft.Jet.OLEDB.4.0; Data Source
= c:\test.2; Extended Properties = text; HDR=YES; FMT=Delimited")

What's an "ISAM"?




My System SpecsSystem Spec
Old 11-08-2006   #2 (permalink)
Roman Kuzmin
Guest


 
 

Re: Using ADO to read a text file

Try this:

$objConnection.Open('Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\temp;Extended Properties="text;HDR=YES;FMT=Delimited"')

--
Thanks,
Roman


My System SpecsSystem Spec
Old 11-08-2006   #3 (permalink)
/\\/\\o\\/\\/ [MVP]
Guest


 
 

Re: Using ADO to read a text file


"Roman Kuzmin" <z@z.z> wrote in message
news:uJGAXE0AHHA.4992@TK2MSFTNGP03.phx.gbl...
> Try this:
>
> $objConnection.Open('Provider=Microsoft.Jet.OLEDB.4.0;Data
> Source=c:\temp;Extended Properties="text;HDR=YES;FMT=Delimited"')
>
> --
> Thanks,
> Roman

as an addition to Roman's anwer

I have some more information and examples about opening and using textfiles
with ADO (and also for using it with other providers like SQL Excel )on my
blog :

that can help you getting started with this

CSV :
http://mow001.blogspot.com/2006/03/w...-part-one.html
http://mow001.blogspot.com/2006/03/w...-part-two.html

Fixed Lenght :

http://mow001.blogspot.com/2006/07/w...881469178.html

Greetings /\/\o\/\/


My System SpecsSystem Spec
Old 11-09-2006   #4 (permalink)
Jacques Barathon [MS]
Guest


 
 

Re: Using ADO to read a text file

"/\/\o\/\/ [MVP]" <mow001@hotmail.NoSpam> wrote in message
news:%23UKSAP3AHHA.1224@TK2MSFTNGP04.phx.gbl...
<...>
> Fixed Lenght :


Did you mean "Fixed Count"? :-)

Jacques

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Read a line from a text file, without loading the entire file inmemory PowerShell
How to read text file VB Script
How to read and write a text file? VB Script
Read a huge text file from bottom up PowerShell
How do I read a text file and sort text by fixed positions? PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46