Generating dBase II DBF File in C# 3.5

2019-03-04 12:07发布

I'm generating dbf file to get imported to legacy systems that only accepts dBase II OR III. My aplication is .Net 3.5. I initially started working with this component VFPOLEDB.1 but it only generate dbf files in dBase V format which isn't backwards compatibily.

Anyone knows a component or driver to generate de dbf file in dBase II or III

Thanks

标签: c# dbf dbase
3条回答
一纸荒年 Trace。
2楼-- · 2019-03-04 12:13

Try issuing a call to execute a script that opens the file, then does

COPY TO {some file} type FOX2X

that should get you the output...

There was another post of a similar all being done via C# through the VFPOleDB and I'll try to find it... Yup, and with credit to @DaveB here's a snippet of his post in Create .DBF in C# code that is readable from Excel (VFP or not)

 string connectionString = @"Provider=VFPOLEDB.1;Data Source=C:\YourDirectory\"; 

    using (OleDbConnection connection = new OleDbConnection(connectionString)) 
    { 
        using (OleDbCommand scriptCommand = connection.CreateCommand()) 
        { 
            connection.Open(); 

            string vfpScript = @"USE TestDBF 
                                 COPY TO OldDBaseFormatFile TYPE Fox2x 
                                USE"; 

            scriptCommand.CommandType = CommandType.StoredProcedure; 
            scriptCommand.CommandText = "ExecScript"; 
            scriptCommand.Parameters.Add("myScript", OleDbType.Char).Value = vfpScript; 
            scriptCommand.ExecuteNonQuery(); 
        } 
    } 

The original post was for someone to be able to open the file in Excel format.

查看更多
Fickle 薄情
3楼-- · 2019-03-04 12:24

ESRI's Shapefile format uses dBase III for storing attribute data. There's a decent implementation in the SharpMap project which you should be able to use independently (careful of the license, though: it's LGPL).

http://code.google.com/p/sharpmapv2/source/browse/trunk/SharpMap.Data.Providers/ShapeFileProvider/DbaseFile.cs

查看更多
爷、活的狠高调
4楼-- · 2019-03-04 12:35

I remember trying to do this very thing several years ago and failing. My solution was to take an existing dBase II file, empty all data, and keep that empty file as a template for when I needed to create a new database.

查看更多
登录 后发表回答