码迷,mamicode.com
首页 > 数据库 > 详细

c# dbf文件读写类

时间:2014-05-05 10:41:06      阅读:994      评论:0      收藏:0      [点我收藏+]

标签:style   class   tar   ext   get   int   

 

 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

c# dbf文件读写类

标签:style   class   tar   ext   get   int   

原文地址:http://www.cnblogs.com/Small-Life/p/3707788.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!