DBF is a format created by Ashton-Tate and can be recognized by ACT, Lipper, FoxPro, Arago, Wordtech, Xbase and other programs related with Database. Although MS Excel has been the most popular data form software application, DBF format data form files still used widely. So sometimes we may have requirements to export data from datatable to DBF. And with Spire.DataExport, we can export datatable to DBF through DataGridView effortlessly!

Download Spire.DataExport (or Spire.Office) with .NET Framework together. Only 2 Simple steps you can finish the whole datatable to DBF exporting process.

Step 1: Load Data Information

Before exporting data from DataTable, we should load data information from data source. And select which information we need export. Through DataGridVew, we even can preview and modify data information. So, in this step, our job is to prepare data which are about to be exported out.

[C#]
	
        private void btnLoad_Click(object sender, EventArgs e)
        {
            using (OleDbConnection oleDbConnection = new OleDbConnection())
            {
                oleDbConnection.ConnectionString = this.textBox1.Text;
                OleDbCommand oleDbCommand = new OleDbCommand();
                oleDbCommand.CommandText = this.textBox2.Text;
                oleDbCommand.Connection = oleDbConnection;
                using (OleDbDataAdapter da = new OleDbDataAdapter(oleDbCommand))
                {
                    DataTable dt = new DataTable();
                    da.Fill(dt);
                    dataGridView1.DataSource = dt;
                }
            }
        }

Effect Screenshot

Datatable to DBF

Step 2: Set Export into DBF

Spire.DataExport allows user to export data into most popular file formats including MS Excel, MS Word, HTML, PDF, XML, CSV, DBF, DIF, etc. Here we need set it as DBF format. Spire.DataExport will create a new DBF file and through DataGridView export data into DBF file. You also can rename the file as you like.

[C#]
        private void btnRun_Click(object sender, EventArgs e)
        {
            Spire.DataExport.DBF.DBFExport DBFExport = new Spire.DataExport.DBF.DBFExport();
            DBFExport.DataSource = Spire.DataExport.Common.ExportSource.DataTable;
            DBFExport.DataTable = this.dataGridView1.DataSource as DataTable;
            DBFExport.ActionAfterExport = Spire.DataExport.Common.ActionType.OpenView;
            DBFExport.FileName = "DBF0401.dbf";
            DBFExport.SaveToFile();
        }
          

Effect Screenshot

Datatable to DBF

Published in Datatable Export