Click here to Skip to main content
15,566,240 members
Home / Discussions / C#
   

C#

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