c# dbf文件读写类

时间:2014-05-05 10:41:06   收藏:0   阅读:994

 

 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();         }     }

c# dbf文件读写类,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!