如何在C#中从头开始创建DBF文件?

Gre*_*reg 9 .net c# dbf .net-2.0

我试图在我的程序中从头开始编写DBF文件.我想创建它,添加一些列,然后将数据添加到X列的次数.我的程序不需要再读它,但其他程序会.

我四处寻找解决方案,但似乎所有人都假设现有的DBF文件,而我想创建一个新文件.

这样做的目的是使DBF成为ESRI ShapeFile的一部分.

有谁知道如何做到这一点?

Jar*_*dek 10

下载用于Visual FoxPro 9.0的Microsoft OLE DB提供程序并使用:

string connectionString = @"Provider=VFPOLEDB.1;Data Source=D:\temp";
using (OleDbConnection connection = new OleDbConnection(connectionString))
using (OleDbCommand command = connection.CreateCommand())
{
    connection.Open();

    OleDbParameter script = new OleDbParameter("script", @"CREATE TABLE Test (Id I, Changed D, Name C(100))");

    command.CommandType = CommandType.StoredProcedure;
    command.CommandText = "ExecScript";
    command.Parameters.Add(script);
    command.ExecuteNonQuery();
}
Run Code Online (Sandbox Code Playgroud)

编辑:OP不需要FoxPro DBF格式,但需要dBase IV格式:

string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\temp;Extended Properties=dBase IV";

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

    command.CommandText = "CREATE TABLE Test (Id Integer, Changed Double, Name Text)";
    command.ExecuteNonQuery();
}
Run Code Online (Sandbox Code Playgroud)