Click here to Skip to main content
15,311,104 members
Home / Discussions / C#
   

C#

 
GeneralRe: C# How to convert my List<T> to Pivot datatable Pin
Mou_kol15-Sep-21 3:49
MemberMou_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
MemberMou_kol15-Sep-21 20:37 
GeneralRe: C# How to convert my List<T> to Pivot datatable Pin
Pete O'Hanlon15-Sep-21 6:52
mvaPete O'Hanlon15-Sep-21 6:52 
GeneralRe: C# How to convert my List<T> to Pivot datatable Pin
BillWoodruff15-Sep-21 8:52
mveBillWoodruff15-Sep-21 8:52 
GeneralRe: C# How to convert my List<T> to Pivot datatable Pin
Mou_kol15-Sep-21 20:20
MemberMou_kol15-Sep-21 20:20 
QuestionHow to store Pivot data into List<T> Pin
Mou_kol14-Sep-21 5:53
MemberMou_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
MemberMou_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 
GeneralRe: How to store Pivot data into List<T> Pin
Mou_kol14-Sep-21 23:14
MemberMou_kol14-Sep-21 23:14 
GeneralRe: How to store Pivot data into List<T> Pin
Richard Deeming14-Sep-21 23:17
mveRichard Deeming14-Sep-21 23:17 
QuestionActive step-two verfication telegram with c# Pin
Nader Rostamkhani8-Sep-21 6:22
MemberNader Rostamkhani8-Sep-21 6:22 
Rant[REPOST] Active step-two verfication telegram with c# Pin
Richard Deeming8-Sep-21 6:33
mveRichard Deeming8-Sep-21 6:33 
QuestionWhat is default unit of EPPlus (point, inches, pixel) Pin
Mou_kol8-Sep-21 4:39
MemberMou_kol8-Sep-21 4:39 
AnswerRe: What is default unit of EPPlus (point, inches, pixel) Pin
Member 153296138-Sep-21 5:22
MemberMember 153296138-Sep-21 5:22 
GeneralRe: What is default unit of EPPlus (point, inches, pixel) Pin
Mou_kol8-Sep-21 21:22
MemberMou_kol8-Sep-21 21:22 
GeneralRe: What is default unit of EPPlus (point, inches, pixel) Pin
Pete O'Hanlon21-Sep-21 0:26
mvaPete O'Hanlon21-Sep-21 0:26 
QuestionOther program access and data extraction Pin
cocaya7-Sep-21 16:48
Membercocaya7-Sep-21 16:48 
Rant[REPOST] Other program access and data extraction Pin
Richard Deeming7-Sep-21 21:24
mveRichard Deeming7-Sep-21 21:24 
GeneralVerification of Information at First Launch Pin
Member 141922165-Sep-21 4:50
MemberMember 141922165-Sep-21 4:50 
GeneralRe: Verification of Information at First Launch Pin
jschell5-Sep-21 8:49
Memberjschell5-Sep-21 8:49 
GeneralRe: Verification of Information at First Launch Pin
OriginalGriff5-Sep-21 10:26
mveOriginalGriff5-Sep-21 10:26 
GeneralRe: Verification of Information at First Launch Pin
Pete O'Hanlon5-Sep-21 10:37
mvaPete O'Hanlon5-Sep-21 10:37 
QuestionAmplitude Meter (trackbar?) Pin
weinerschizel4-Sep-21 6:49
Memberweinerschizel4-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.