2014-03-27 14 views
1

我有一個類,其中的方法將被用作Web服務(REST) - > XML輸出。它用於從db中獲取一些數據,這些數據可以用於從excel導入。如何用一種方法返回多個表?

雖然我不得不返回只是一個表,也沒有問題(方法如下所示):

public DataTable CountryKitUPH(string date, string fhour, string thour) 
{ 
    date = Dates(date); 

    var from = date + ' ' + fhour + ":00"; 
    var to = date + ' ' + thour + ":00"; 

    var sqlCommand = "exec rptPMCountryKitUPH_sp @trantype='REPORT', @fromdt='" + from + "', @todt='" + to + "'"; 

    var dataContext = DataContextFactory.GetShopFloorDataContext(Guid.Empty); 
    var dt = Core.Data.Utility.QueryToDataTable(Guid.Empty, DataContextFactory.SecurityKey, sqlCommand); 
    dt.TableName = "Country Kit UPH"; 
    return dt; 
} 

但現在我需要做的報告,該報告將返回多個表 - 一組爲每個表「行」參數。

而該方法應該返回更多的那些。我能想象它怎麼會像XML,我只是不知道如何返回它(和我不能發表圖片呢,我會嘗試寫我是怎麼想的XML應該是這樣的:

<line name='L1'> 
    <minitable> 
     <row no="1"> 
      <column name="event 1">13</column> 
      <column name="event 2">35</column> 
      <column name="event 3">78</column> 
     </row> 
    </minitable> 
    <table> 
     (content) 
    </table> 
</line> 
<line name='L2'> 
    <minitable> 
     (content) 
    </minitable> 
    <table> 
     (content) 
    </table> 
</line> 

所以請 - 我應該選擇什麼樣的數據類型來返回多個表這樣的,或者,如何包裝這些在XML

非常感謝

+0

列表似乎李?如果你需要它們作爲數據表,並且你已經有了你的代碼設置來獲取數據表,那將是合適的。 – Kevin

回答

1

像這樣的東西

public DataTable[] MultipleMethod(args) 
{ 
    List<DataTable> list = new List<DataTable>(); 

    // Load first DataTable 
    DataTable dt = ... 
    list.Add(dt); // Add the DataTable to the list of tables 

    // Load second DataTable 
    dt = ... 
    list.Add(dt); // Add the DataTable to the list of tables 

    // Load another DataTable 
    dt = ... 
    list.Add(dt); // Add the DataTable to the list of tables 

    return list.ToArray(); // Return an array of tables (can return the list if that is the return type) 
} 
相關問題