Export Table to dBase 3 (.dbf)

S

Stephan Zaubzer

Hi!

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

Regards
Stephan
 
P

Paul Clement

¤ 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)
 
S

Stephan Zaubzer

The data comes from a select statement which selects certain columns of
certain rows of a table.
Regards
Stephan
 
T

Thomas Weingartner

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
 
P

Paul Clement

¤ 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)
 
J

jools_h

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top