Read a DBF file

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


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)

$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
Write-Host “Contents of the DataTable”


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: (:slight_smile: [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException

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

Sorry for my bad English …

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.

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=;")

Not sure if that helps or not