Adding sorted list to DataTable Row

Adding sorted list to DataTable Row

Benjoe64Benjoe64 Posts: 4Questions: 3Answers: 1
edited November 2019 in Free community support

I am trying to add IEnumerable items of strings 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.

private void addToDataTable<T>(IEnumerable<T> rDataRow, string dataRowType)
        {
            try
            {
                foreach (var r in rDataRow)
                {
                var type = r.GetType();
                 DataRow dr = reportData.NewRow();
                 
                  var ListItems = "";                            
                       

                        if (type.GetProperty("admin") != null)
                        {
                            foreach (var t in (IEnumerable)type.GetProperty("admin").GetValue(r, null))
                            {

                                ListItems += t;
                            }
                            dr.SetField(dcAdmin, ListItems);
                        }
                        reportData.Rows.Add(dr);
                }
            }
        }

Edited by Kevin:  Syntax highlighting. Details on how to highlight code using markdown can be found in this guide

This discussion has been closed.