Read a DBF file

Welcome Forums General PowerShell Q&A Read a DBF file

This topic contains 1 reply, has 2 voices, and was last updated by

2 years, 10 months ago.

  • Author
  • #5639

    Points: 0
    Rank: Member

    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 :

    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

    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.

  • #35888

    Points: 57
    Rank: Member

    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

The topic ‘Read a DBF file’ is closed to new replies.