Kwasi Denkyira

Kwasi Denkyira

  • 1.2k
  • 197
  • 15.1k

Adding sorted list to DataTable Row

Nov 2 2019 4:25 PM
I am trying to add IEnumerable items of string to a datatable row, but can't get it sorted. I want to get an output of 
 
james,john
Mary,Ann
Edward,Anthony
 
but I am getting  james,johnMary,AnnEdward,Anthony
Below is my code. Any help will be appreciated.
 
  1. private void addToDataTable<T>(IEnumerable<T> rDataRow, string dataRowType)  
  2.        {  
  3.            try  
  4.            {  
  5.                foreach (var r in rDataRow)  
  6.                {  
  7.             var type = r.GetType();  
  8.                 DataRow dr = reportData.NewRow();  
  9.                
  10.               var ListItems = "";                              
  11.                         
  12.   
  13.                        if (type.GetProperty("admin") != null)  
  14.                        {  
  15.                            foreach (var t in (IEnumerable)type.GetProperty("admin").GetValue(r, null))  
  16.                            {  
  17.   
  18.                                ListItems += t;  
  19.                            }  
  20.                            dr.SetField(dcAdmin, ListItems);  
  21.                        }  
  22.                        reportData.Rows.Add(dr);  
  23.             }  
  24.         }  
  25.     }  
 

Answers (2)