我正在尝试在我的程序中从头开始编写一个 DBF 文件。我想创建它,添加一些列,然后将数据添加到列 X 次。我的程序不需要再次读入它,但其他程序需要。
我四处寻找解决方案,但似乎都假设有一个现有的 DBF 文件,而我想创建一个新文件。
这样做的目的是使 DBF 成为 ESRI ShapeFile 的一部分。
有人知道怎么做吗?
最佳答案
下载Microsoft OLE DB Provider for Visual FoxPro 9.0并使用:
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();
}
编辑: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();
}
关于c# - 如何在 C# 中从头开始创建 DBF 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4932530/