How to create a DBF file from scratch in C#?

前端 未结 3 582
悲哀的现实
悲哀的现实 2020-12-16 01:53

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 ne

3条回答
  •  情书的邮戳
    2020-12-16 02:20

    Download Microsoft OLE DB Provider for Visual FoxPro 9.0 and use:

    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();
    }
    

    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();
    }
    

提交回复
热议问题