Transpose a datatable

后端 未结 3 724
情话喂你
情话喂你 2020-12-22 08:31

I have the data table below. I would like to change the data table to transform the data table into the one next to it. How can I do this?

The reason why i would lik

3条回答
  •  长情又很酷
    2020-12-22 09:28

    .NET does not include a method to transpose data tables. You have to make your own. This website has a tutorial on an example transpose method. I will copy and paste the code snippet below:

    private DataTable Transpose(DataTable dt)
    {
        DataTable dtNew = new DataTable();
    
        //adding columns    
        for(int i=0; i<=dt.Rows.Count; i++)
        {
           dtNew.Columns.Add(i.ToString());
        }
    
    
    
        //Changing Column Captions: 
        dtNew.Columns[0].ColumnName = " ";
    
         for(int i=0; i

提交回复
热议问题