Wednesday, March 31, 2010

Reading .DBF Files with .NET (Using Oledb Provider)

You can also use OleDb Provider for reading .DBF files:

System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection();


DataTable dt = new
DataTable();

conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;" +


@"Data Source=C:\dbfFilesFolder;Extended Properties=dBase IV";

conn.Open();

System.Data.OleDb.OleDbCommand comm = new System.Data.OleDb.OleDbCommand();

comm.CommandText = "SELECT * FROM C:\\dbfFilesFolder\\FileName";

comm.Connection = conn;


dt.Load(comm.ExecuteReader());


//After this, you have data from your DBF file in your DataTable;


conn.Close();

Tuesday, March 30, 2010

Reading DBF files from .NET

Recently I have to develop quick report based on legacy data from .DBF file.
There was no much time, so I decided to do that in c# using ODBC.net data provider. This post shows one way of loading DBF table in DataTable object.

System.Data.Odbc.OdbcConnection conn = new System.Data.Odbc.OdbcConnection();
//short connection string ( but works )
conn.ConnectionString = @"DSN=dBase Files";

conn.Open();

System.Data.Odbc.OdbcCommand comm = new System.Data.Odbc.OdbcCommand();
comm.CommandText = "SELECT * FROM c:\\folder\\fileName.dbf" ;

comm.Connection = conn;
DataTable dt = new DataTable();
dt.Load(comm.ExecuteReader());
conn.Close();
//after this you cab do what you want with the data table
Short reminder:
Windows 2000 Professional and Windows 2000 Server are approaching 10 years since their launch and both products will go out of support on July 13, 2010.

Windows XP was launched back in 2001. While support for the product will continue, Service Pack 2 will go out of support on July 13, 2010. From that date onwards, Microsoft will no longer support or provide free security updates for Windows XP SP2. Please install the free Service Pack 3 for Windows XP to have the most secure and supported Windows XP platform.

Finally, Windows Vista with no Service Packs installed will end support on April 13 2010. Please install the free Service Pack 2 for Windows Vista to have the most secure and supported Windows Vista platform.