views:

248

answers:

4

I have class which has a method that needs to return three DataTables. I thought I could use Generics but honestly I've never used them, so I'm trying figure it out. It may not be the right thing here.

I have in my class Employee:

public List<Employee> GetEmployees()
{
  //calls to other methods in my class;
  //psuedocode
  GetDataTable1;
  GetDataTable2;
  GetDataTable3;

  return all three datatables;
}

On my presentation side I have three gridviews:

I create my class Employee and call GetEmployees and get back my list of DataTable, then

gridview1.datasource = datatable1;
gridview2.datasource = datatable2;
gridview3.datasource = datatable3;

I'm not sure how to proceed. I have tried the class method definition above but I'm not getting it right.

Hoping for advice. I do not wish to use three methods. I am using C# and asp.net 2.0.

Thank you.

+10  A: 

You can add them all to a DataSet and return that

scottm
+5  A: 

You can use a DataSet, which is designed to hold multiple DataTable objects and reference them by name.

Welbog
+3  A: 

I would think it's the same way you'll return 3 variables from a method:

  • return a collection
  • create a structure to hold the 3 results
  • use out parameters
Tundey
Note that .Net already has a purpose-built collection or structure in the form of a dataset for items 1 or 2 on that list.
Joel Coehoorn
A: 

Return New DataTable() {Me.GetDataTable1, Me.GetDataTable2, Me.GetDataTable3}

yeah its vb shrug

EthR