Author Posts

January 1, 2012 at 12:00 am

by Sweet at 2013-03-07 09:17:39

Hi,

I tried to read a DBF file for search and replace a string by another but I don't succeeded to read a simple database for the moment.

In the folder "D:\Scripts" I have a file named : "DETAIL_I.DBF".

Here is my code :

$ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Scripts;Extended Properties=dBASE IV;"
$Conn = new-object System.Data.OleDb.OleDbConnection($connString)
$conn.open()

$cmd = new-object System.Data.OleDb.OleDbCommand("select * from DETAIL_I",$Conn)
$da = new-object System.Data.OleDb.OleDbDataAdapter($cmd)
$dt = new-object System.Data.dataTable
$da.fill($dt)
Write-Host "Contents of the DataTable"
$dt

$conn.close()

I have launched my powershell in 32Bits for use this provider but i have this error message :

[quote]Exception calling « Fill » with « 1 » argument (s): « The external table is not in the expected format. »
At line: 1 char: 9
+ $da.fill < <<< ($dt)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
[/quote]

Someone can help me ?
Thanks in advance for your help.

Sorry for my bad English ...

Sweet

by DonJ at 2013-03-07 09:30:26

The provider is not able to read the file. There isn't much you can do about that.

Consider posting on StackOverflow; although you're using PowerShell, this isn't really something in PowerShell itself. The folks on StackOverflow are mostly developers and someone may have run into this.

March 1, 2016 at 1:52 pm

I was able to open the file with the 32bit version of powershell using this command:

$conn = new-object System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\temp\dbf;Extended Properties=dBASE IV;User ID=;Password=;")
$conn.open()

Not sure if that helps or not