0

I have to group all itens in a Datatable according a status, i have only the DataTable with all amount of data.

DataTable results;
using (var sqlDataAccess = new MSQLDataAccess(Util.GetIntegraConnectionString))
{
    results = sqlDataAccess.GetDataTable(query, parameters);
}

The results variable have this data:

DBSMP.DTINICIOPREV
DBSMP.DTFIMPREV
DBSMP.CIDADE_DES 
DBSMP.CIDADE_ORI
DBSMP.REF2
WORK.DESCRIPTION <<-- Group here
TRA.FANTASIA

I have to group by WORK.DESCRIPTION, and present this data like this:



HOUSES = 3

DTINICIOPREV | DTFIMPREV |CIDADE_DES | CIDADE_ORI | REF2 | FANTASIA 
DATA HERE DATA HERE DATA HERE DATA HERE DATA HERE DATA HERE DATA HERE  
DATA HERE DATA HERE DATA HERE DATA HERE DATA HERE DATA HERE DATA HERE  
DATA HERE DATA HERE DATA HERE DATA HERE DATA HERE DATA HERE DATA HERE  

FLATS = 5

DTINICIOPREV | DTFIMPREV |CIDADE_DES | CIDADE_ORI | REF2 | FANTASIA 
DATA HERE DATA HERE DATA HERE DATA HERE DATA HERE DATA HERE DATA HERE  
DATA HERE DATA HERE DATA HERE DATA HERE DATA HERE DATA HERE DATA HERE  
DATA HERE DATA HERE DATA HERE DATA HERE DATA HERE DATA HERE DATA HERE 
DATA HERE DATA HERE DATA HERE DATA HERE DATA HERE DATA HERE DATA HERE  
DATA HERE DATA HERE DATA HERE DATA HERE DATA HERE DATA HERE DATA HERE 

Then which is the best approach to turn results into several lists of grouped data?

ekad
  • 14,436
  • 26
  • 44
  • 46
guisantogui
  • 4,017
  • 9
  • 49
  • 93
  • The whole point here is the SQL query (which you are not writing). Why retrieving data from a DB and then wasting type on reordering everything in C#? Get the data ordered directly by adding the GROUP BY statement to your query. http://www.w3schools.com/sql/sql_groupby.asp – varocarbas Sep 02 '13 at 19:19
  • If I use this approach I'll have to make one select per status, to retrieve a lot of lists with this separated data. – guisantogui Sep 02 '13 at 19:42
  • I thought that you were reading all the data from the DB once and then wanted to change the table storing all the records in C# (results). If you have to make multiple queries to the DB, perhaps this is not the best approach. Although you might use the "SQL-querying equivalent" in C# (LINQ) to do basically the same. Here you have a link to group by in LINQ -> http://stackoverflow.com/questions/7325278/group-by-in-linq – varocarbas Sep 02 '13 at 19:45

0 Answers0