Re: Export Table to dBase 3 (.dbf) by Thomas
Thomas
Sun Oct 01 10:48:36 CDT 2006
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 =3D OpenConnection(directory);
}
internal IDbConnection OpenConnection(string directoryName)=20
{
string connectionString =3D @"Provider=3DMSDASQL;Driver=3D{Microsof=
t dBase Driver (*.dbf)};DBQ=3D" + directoryName;
try=20
{
OdbcConnection conn =3D new OdbcConnection(connectionString);
conn.Open();
return conn;
}
catch (Exception)=20
{
// If you need your Exception handling, it goes here; if not
// forget about the try..catch statements.
throw;
}
}
public int Execute(string sql)=20
{
using(IDbCommand cmd =3D m_conn.CreateCommand())
{
cmd.CommandText =3D sql;
return cmd.ExecuteNonQuery();
}
}
public void Close()
{
m_conn.Close();
}
}
and you call from outside:
...
DBaseConnector connector =3D new DBaseConnector(m_destinationDir);
try
{
connector.Execute("INSERT INTO MyDbaseTable ...");
...
}
finally
{
connector.Close();
}
Greetings from Switzerland
Thomas
On Fri, 29 Sep 2006 17:49:25 +0200
Stephan Zaubzer <stephan.zaubzer@schendl.at> wrote:
> The data comes from a select statement which selects certain columns of=20
> certain rows of a table.
> Regards
> Stephan
>=20
> Paul Clement wrote:
> > On Fri, 29 Sep 2006 14:25:42 +0200, Stephan Zaubzer <stephan.zaubzer@sc=
hendl.at> wrote:
> >=20
> > =A4 Hi!
> > =A4=20
> > =A4 Does anybody know the best way how to export a DataTable to a dBase=
3 file?
> > =A4=20
> >=20
> > 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)?
> >=20
> >=20
> > Paul
> > ~~~~
> > Microsoft MVP (Visual Basic)