如何从头开始创建在C#中的DBF文件? [英] How to create a DBF file from scratch in C#?
问题描述
我想在我的计划从头开始写一个DBF文件。我要创建它,添加一些列,然后将数据添加到次列x量。我的计划将不再需要读取它了,但其它的程序。
I am trying to write a DBF file from scratch in my program. I want to create it, add some columns, and then add data to the columns X amount of times. My program will not need to read it in again, but other programs will.
我环顾四周,一个解决办法,但似乎都认为现有的DBF文件,而我想拍一个新的。
I've looked around for a solution to this, but all seem to assume an existing DBF file, whereas I want to make a new one.
这样做的目的是使ESRI shape文件的DBF部分。
The purpose of this is to make the DBF part of an ESRI ShapeFile.
有谁知道如何做到这一点?
Does anyone know how to do this?
推荐答案
下载<一个href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=e1a87d8f-2d58-491f-a0fa-95a3289c5fd4">Microsoft OLE DB提供程序的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();
}
修改:不想要的FoxPro DBF格式,但OP dBase IV资料格式为:
Edit: The OP does not want a FoxPro DBF format but dBase IV format:
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#中的DBF文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!