Export Table to dBase 3 (.dbf)

  • Thread starter Thread starter Stephan Zaubzer
  • Start date Start date
S

Stephan Zaubzer

Hi!

Does anybody know the best way how to export a DataTable to a dBase 3 file?

Regards
Stephan
 
¤ Hi!
¤
¤ Does anybody know the best way how to export a DataTable to a dBase 3 file?
¤

What is the data source of the DataTable? Do you need to change any of the data or can it be
exported directly from the other data source (assuming there is one)?


Paul
~~~~
Microsoft MVP (Visual Basic)
 
The data comes from a select statement which selects certain columns of
certain rows of a table.
Regards
Stephan
 
Hi Stephan

We have used the ODBC Driver to write dBase files. I think it was dBase IV or V. You have to try, if it works for you with dBase 3.

Here is an example code, we have used with .NET 2.0:

using System;
using System.Data;
using Microsoft.Data.Odbc;

public class DBaseConnector
{
private IDbConnection m_conn;

public DBaseConnector(string directory)
{
m_conn = OpenConnection(directory);
}

internal IDbConnection OpenConnection(string directoryName)
{
string connectionString = @"Provider=MSDASQL;Driver={Microsoft dBase Driver (*.dbf)};DBQ=" + directoryName;
try
{
OdbcConnection conn = new OdbcConnection(connectionString);
conn.Open();
return conn;
}
catch (Exception)
{
// If you need your Exception handling, it goes here; if not
// forget about the try..catch statements.
throw;
}
}

public int Execute(string sql)
{
using(IDbCommand cmd = m_conn.CreateCommand())
{
cmd.CommandText = sql;
return cmd.ExecuteNonQuery();
}
}

public void Close()
{
m_conn.Close();
}
}

and you call from outside:

....
DBaseConnector connector = new DBaseConnector(m_destinationDir);
try
{
connector.Execute("INSERT INTO MyDbaseTable ...");
...
}
finally
{
connector.Close();
}


Greetings from Switzerland
Thomas
 
¤ The data comes from a select statement which selects certain columns of
¤ certain rows of a table.
¤ Regards
¤ Stephan
¤

What kind of database are you selecting from?


Paul
~~~~
Microsoft MVP (Visual Basic)
 
If the source data is from a SQL Server database then you could use DTS
to transform the data into your .dbf. Very powerful and very easy (
you can even select data as part of the transformation services)
 
Back
Top