/// <summary> /// The get data table. /// </summary> /// <param name="tableName"> /// The table name. /// </param> /// <returns> /// The <see cref="DataTable"/>. /// </returns> public DataTable GetDataTable(string tableName) { try { DataTable dataTable = new DataTable(); OleDbConnection oleDbConnection = new OleDbConnection(this.ConnectionString); oleDbConnection.Open(); if (oleDbConnection.State == ConnectionState.Open) { OleDbDataAdapter oleDbDataAdapter = new OleDbDataAdapter("select * from " + tableName, oleDbConnection); oleDbDataAdapter.Fill(dataTable); } return(dataTable); } catch (Exception ex) { GetDataTableException getDataTableException = new GetDataTableException("Get data table failed", ex); getDataTableException.Data.Add("table", tableName); getDataTableException.Data.Add("connection", this.ConnectionString); throw getDataTableException; } }
/// <summary> /// The get data table. /// </summary> /// <param name="directoryName"> /// The directory name. /// </param> /// <param name="tableName"> /// The table name. /// </param> /// <returns> /// The <see cref="DataTable"/>. /// </returns> /// <exception cref="InvalidDataSourceException"> /// </exception> /// <exception cref="GetDataTableException"> /// </exception> /// <exception cref="Exception"> /// </exception> public DataTable GetDataTable(string directoryName, string tableName) { string connectionString = string.Format(this.connectionStringPattern, directoryName); try { DataTable dataTable = new DataTable(); this.oleDbConnection = new OleDbConnection(connectionString); this.oleDbConnection.Open(); if (this.oleDbConnection.State == ConnectionState.Open) { OleDbDataAdapter oleDbDataAdapter = new OleDbDataAdapter( "select * from " + tableName, this.oleDbConnection); oleDbDataAdapter.Fill(dataTable); } return(dataTable); } catch (Exception ex) { if (ex is OleDbException) { if (ex.Message == "Invalid path or file name.") { InvalidDataSourceException invalidDataSourceException = new InvalidDataSourceException("Invalid data source exception", ex); invalidDataSourceException.Data.Add("dataSource", directoryName); invalidDataSourceException.Data.Add("connection", connectionString); throw invalidDataSourceException; } else { // File 'pp_cntry.dbf' does not exist. GetDataTableException getDataTableException = new GetDataTableException( "Get data table failed", ex); getDataTableException.Data.Add("table", tableName); getDataTableException.Data.Add("connection", connectionString); throw getDataTableException; } } else { throw ex; } throw; } finally { this.oleDbConnection.Close(); } }