c# dbf文件读写类
public class DbfReader {
private string _path;
private OleDbConnection _connection;
public DbfReader(string dbfPath) {
_path = dbfPath;
CheckFile();
}
public OleDbDataReader GetReader()
{
try
{
_connection.Open();
OleDbCommand command = new OleDbCommand("select * from [" + _path + ‘]‘, _connection);
return command.ExecuteReader(CommandBehavior.CloseConnection);
}
catch
{
return null;
throw;
}
}
public void Close()
{
_connection.Close();
}
public void CheckFile()
{
_connection = new OleDbConnection("provider=vfpoledb.1;data source=" + _path);
try
{
_connection.Open(); } catch { throw new EMException(1103); } finally { _connection.Close(); } } }
public class DbfWriter { private string _path; public string TableName; private string _createCommand; private OleDbConnection _connection; private OleDbCommand _command; public DbfWriter(string dbfPath, string createCommand) { _path = dbfPath; _createCommand = createCommand; } public void Open() { int index = _path.LastIndexOf(‘\\‘); TableName = _path.Substring(index + 1); _connection = new OleDbConnection("provider=vfpoledb.1;data source=" + _path.Substring(0, index)); _command = new OleDbCommand("create table [" + TableName + "] " + _createCommand, _connection); try { _connection.Open(); _command.ExecuteNonQuery(); } catch { _connection.Close(); throw; } } public void Close() { _connection.Close(); } public void AppendData(string command) { _command.CommandText = command; _command.ExecuteNonQuery(); } }