Question

I'm trying to use *.dbf (dBase IV) file to fetch some needed geodata from it (shapefiles).

The strange thing is that dBase JET OleDb 4.0 provider is telling me, that there isn't such an object, but it does exist!

Proof:

http://s21.postimg.org/eaj4h91uv/image.png

Source-code:

    static void Test()
    {
        const string path = "C:\\buildings.dbf";
        string conStr = String.Format("Provider = Microsoft.Jet.Oledb.4.0; Data Source = {0}; Extended Properties = \"dBase IV\"", Path.GetDirectoryName(path));

        var connection = new OleDbConnection(conStr);
        connection.Open();

        var command = new OleDbCommand(string.Format("select NAME from {0}", Path.GetFileName(path)), connection);

        using (var reader = command.ExecuteReader())
        {
            while (reader.Read())
            {
                var str = (string)reader["NAME"];
            }
        }

        connection.Close();
    }

    static void Main()
    {
        try
        {
            Test();
        }
        catch (Exception exc)
        {
            Console.WriteLine(exc);
        }
    }
Was it helpful?

Solution

It APPEARS you have a good connection string... The connection string should point to the PATH ONLY where the .dbf files are located. However, even as a test, having this .dbf file in the ROOT of C:\ MIGHT be posing as a problem, I would for grins, just move it into a sub-folder off the root, such as C:\TEST\buildings.dbf

Next, the query once connection is open to the current "path", it can see any .dbf table in that path. You should only need

var command = new OleDbCommand("select NAME from buildings", connection);

The ".dbf" is implied for querying. The only other problem that MIGHT be causing the problem is 'NAME' is a reserved word and probably needs name (tics) wrapped around it so it knows the actual COLUMN NAME and not the reserved word.

Different providers may have issue with the tic marks, so you may need to wrap in [name] square brackets instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top