Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Using ADO with a text file

Closed Thread
 
Thread Tools Display Modes
Old 11-08-2006   #1 (permalink)
Marco Shaw
Guest


 

Using ADO with a text file

What am I doing wrong?

Wouldn't the steps below create text file with a header of "Name", which I
could use in turn to query on that column?

PS C:\> echo "Name" > data.txt
PS C:\> echo "Test" >> data.txt
PS C:\> gc data.txt
Name
Test
PS C:\> $adOpenStatic = 3
PS C:\> $adLockOptimistic = 3
PS C:\> $adCmdText = 1
PS C:\>
PS C:\> $objConnection = New-Object -comobject ADODB.Connection
PS C:\> $objRecordset = New-Object -comobject ADODB.Recordset
PS C:\>
PS C:\> $objConnection.Open("Provider = Microsoft.Jet.OLEDB.4.0; Data Source
= c:\\; Extended Properties = `"Text;HDR=Ye
s; FMT=Delimited`"")
PS C:\> $objRecordset.Open("Select * from data.txt",
$objConnection,$adOpenStatic,$adLockOptimistic,$adCmdText)
PS C:\> $objRecordset.MoveFirst()
PS C:\>
PS C:\> do {$objRecordset.Fields.Item("Name").Value;
$objRecordset.MoveNext()} until
>> ($objRecordset.EOF -eq $True)
>>

Exception getting "Item": "Exception calling "get_Item" with "1"
argument(s): "Item cannot be found in the collection c
orresponding to the requested name or ordinal.""
At line:1 char:30
+ do {$objRecordset.Fields.Item( <<<< "Name").Value;
$objRecordset.MoveNext()} until
Exception getting "Item": "Exception calling "get_Item" with "1"
argument(s): "Item cannot be found in the collection c
orresponding to the requested name or ordinal.""
At line:1 char:30
+ do {$objRecordset.Fields.Item( <<<< "Name").Value;
$objRecordset.MoveNext()} until
Exception getting "Item": "Exception calling "get_Item" with "1"
argument(s): "Item cannot be found in the collection c
orresponding to the requested name or ordinal.""
At line:1 char:30
+ do {$objRecordset.Fields.Item( <<<< "Name").Value;
$objRecordset.MoveNext()} until
Exception getting "Item": "Exception calling "get_Item" with "1"
argument(s): "Item cannot be found in the collection c
orresponding to the requested name or ordinal.""
At line:1 char:30
+ do {$objRecordset.Fields.Item( <<<< "Name").Value;
$objRecordset.MoveNext()} until


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


 

Re: Using ADO with a text file

> PS C:\> $objConnection.Open("Provider = Microsoft.Jet.OLEDB.4.0; Data
> Source = c:\\; Extended Properties = `"Text;HDR=Ye
> s; FMT=Delimited`"")


I changed the above to HDR=No, and created a Schema.ini:

PS C:\> gc data.txt
Test
PS C:\> $adOpenStatic = 3
PS C:\> $adLockOptimistic = 3
PS C:\> $adCmdText = 1
PS C:\>
PS C:\> $objConnection = New-Object -comobject ADODB.Connection
PS C:\> $objRecordset = New-Object -comobject ADODB.Recordset
PS C:\> gc Schema.ini
[data.txt]
Col1=Name Text
PS C:\> $objConnection.Open("Provider = Microsoft.Jet.OLEDB.4.0; Data Source
= c:\\; Extended Properties = `"Text;HDR=No
; FMT=Delimited`"")
PS C:\> $objRecordset.Open("Select Name from data.txt",
$objConnection,$adOpenStatic,$adLockOptimistic,$adCmdText)
PS C:\> $objRecordset.MoveFirst()
PS C:\>
PS C:\> do {$objRecordset.Fields.Item("Name").Value;
$objRecordset.MoveNext()} until
>> ($objRecordset.EOF -eq $True)
>> ($objRecordset.EOF -eq $True)
>>



[end]

No more error... No output either.

Any ideas anyone?


Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I read a text file and sort text by fixed positions? Cornelius PowerShell 5 07-20-2007 06:34 PM
find file containing text inside the file rgrainer Vista file management 8 05-20-2007 08:05 PM
5536 rar file - 2.58 gb downloaded only 14kb text file inside =?Utf-8?B?UXVpY2tDaGVlc2U=?= Vista General 9 09-02-2006 05:57 AM
5536 *.rar 2.58gb file turned into 14kb text file. =?Utf-8?B?UXVpY2tDaGVlc2U=?= Vista General 5 08-30-2006 07:23 PM
5536 *.rar file - 2.58gb's but only a 14kb text file inside =?Utf-8?B?UXVpY2tDaGVlc2U=?= Vista General 0 08-30-2006 05:32 PM








Vistax64.com 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 2005-2008

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 47 48 49 50