Click here to Skip to main content
15,891,847 members
Home / Discussions / C#
   

C#

 
GeneralRe: C# Confusion about LINQ Grouping Pin
Mou_kol15-Sep-21 3:51
Mou_kol15-Sep-21 3:51 
GeneralRe: C# Confusion about LINQ Grouping Pin
Richard Deeming15-Sep-21 4:15
mveRichard Deeming15-Sep-21 4:15 
AnswerRe: C# Confusion about LINQ Grouping Pin
BillWoodruff15-Sep-21 19:35
professionalBillWoodruff15-Sep-21 19:35 
GeneralRe: C# Confusion about LINQ Grouping Pin
Mou_kol15-Sep-21 20:22
Mou_kol15-Sep-21 20:22 
GeneralRe: C# Confusion about LINQ Grouping Pin
Dave Kreskowiak16-Sep-21 2:25
mveDave Kreskowiak16-Sep-21 2:25 
GeneralRe: C# Confusion about LINQ Grouping Pin
Mou_kol16-Sep-21 6:30
Mou_kol16-Sep-21 6:30 
GeneralRe: C# Confusion about LINQ Grouping Pin
Mou_kol15-Sep-21 20:39
Mou_kol15-Sep-21 20:39 
QuestionC# How to convert my List<T> to Pivot datatable Pin
Mou_kol14-Sep-21 6:00
Mou_kol14-Sep-21 6:00 
AnswerRe: C# How to convert my List<T> to Pivot datatable Pin
Richard Deeming14-Sep-21 6:56
mveRichard Deeming14-Sep-21 6:56 
GeneralRe: C# How to convert my List<T> to Pivot datatable Pin
BillWoodruff14-Sep-21 19:29
professionalBillWoodruff14-Sep-21 19:29 
GeneralRe: C# How to convert my List<T> to Pivot datatable Pin
Mou_kol14-Sep-21 21:05
Mou_kol14-Sep-21 21:05 
GeneralRe: C# How to convert my List<T> to Pivot datatable Pin
Mou_kol14-Sep-21 22:50
Mou_kol14-Sep-21 22:50 
GeneralRe: C# How to convert my List<T> to Pivot datatable Pin
Richard Deeming14-Sep-21 23:15
mveRichard Deeming14-Sep-21 23:15 
GeneralRe: C# How to convert my List<T> to Pivot datatable Pin
Mou_kol14-Sep-21 23:54
Mou_kol14-Sep-21 23:54 
GeneralRe: C# How to convert my List<T> to Pivot datatable Pin
Richard Deeming15-Sep-21 0:38
mveRichard Deeming15-Sep-21 0:38 
GeneralRe: C# How to convert my List<T> to Pivot datatable Pin
Mou_kol15-Sep-21 3:49
Mou_kol15-Sep-21 3:49 
GeneralRe: C# How to convert my List<T> to Pivot datatable Pin
Richard Deeming15-Sep-21 4:13
mveRichard Deeming15-Sep-21 4:13 
GeneralRe: C# How to convert my List<T> to Pivot datatable Pin
Mou_kol15-Sep-21 20:37
Mou_kol15-Sep-21 20:37 
GeneralRe: C# How to convert my List<T> to Pivot datatable Pin
Pete O'Hanlon15-Sep-21 6:52
mvePete O'Hanlon15-Sep-21 6:52 
GeneralRe: C# How to convert my List<T> to Pivot datatable Pin
BillWoodruff15-Sep-21 8:52
professionalBillWoodruff15-Sep-21 8:52 
GeneralRe: C# How to convert my List<T> to Pivot datatable Pin
Mou_kol15-Sep-21 20:20
Mou_kol15-Sep-21 20:20 
QuestionHow to store Pivot data into List<T> Pin
Mou_kol14-Sep-21 5:53
Mou_kol14-Sep-21 5:53 
AnswerRe: How to store Pivot data into List<T> Pin
Richard Deeming14-Sep-21 6:04
mveRichard Deeming14-Sep-21 6:04 
Your class is designed to store the un-pivoted data. You'll need to change your query so that it doesn't pivot the data before you load it.

The alternative would be to redesign your class:
C#
public class Header
{
    public string Section { get; set; }
    public string LineItem { get; set; }
    public string BrokerCode { get; set; }
    public string BrokerName { get; set; }
    public List<PeriodTotal> Periods { get; set; }
}

public class PeriodTotal
{
    public string Period { get; set; }
    public decimal PeriodValue { get; set; }
}
C#
var result = new List<Header>();

using (var reader = command.ExecuteReader())
{
    while (reader.Read())
    {
        string section = reader.GetString(0);
        string lineItem = reader.GetString(1);
        string brokerCode = reader.GetString(2);
        string brokerName = reader.GetString(3);
        
        var periods = new List<PeriodTotal>();
        for (int index = 4; index < reader.FieldCount; index++)
        {
            periods.Add(new PeriodTotal { Period = reader.GetName(index), PeriodValue = reader.GetDecimal(index) });
        }
        
        result.Add(new Header
        {
            Section = section,
            LineItem = lineItem,
            BrokerCode = brokerCode,
            BrokerName = brokerName,
            Periods = periods,
        });
    }
}




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

GeneralRe: How to store Pivot data into List<T> Pin
Mou_kol14-Sep-21 6:29
Mou_kol14-Sep-21 6:29 
GeneralRe: How to store Pivot data into List<T> Pin
Richard Deeming14-Sep-21 6:49
mveRichard Deeming14-Sep-21 6:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.