Using the Fill(DataTable/DataSet) Method

The Fill() method is provided to support systems that are designed around DataSet and DataTable objects rather than custom collections of objects.

The first example illustrates filling a DataTable with data:

   1:  public static DataTable GetFaqByCategory(Lookup<byte> category) {
   5:      DataTable table = new DataTable();
   6:   
   7:      using (SqlConnection connection = new SqlConnection(ApplicationState.ConnectionString)) {
   8:          using (SelectFaqByCategoryIdAdapter adapter = new SelectFaqByCategoryIdAdapter(connection)) {
   9:              adapter.CategoryId = category.PrimaryKey.Value;
  10:              adapter.Fill(table);
  11:          }
  12:      }
  13:   
  14:      return table;
  15:  }

The second example illustrates filling a DataSet with data:

   1:  public static DataSet GetFaqByCategory(Lookup<byte> category) {
   5:      DataSet dataSet = new DataSet();
   6:   
   7:      using (SqlConnection connection = new SqlConnection(ApplicationState.ConnectionString)) {
   8:          using (SelectFaqByCategoryIdAdapter adapter = new SelectFaqByCategoryIdAdapter(connection)) {
   9:              adapter.CategoryId = category.PrimaryKey.Value;
  10:              adapter.Fill(dataSet);
  11:          }
  12:      }
  13:   
  14:      return dataSet;
  15:  }

As with the ExecuteReader() methods, the column ordinal position constants defined by each adapter make accessing columns faster and easier.