You have two options like bellow
1 If you are using SQL Server, write a pivot query that can transpose the result set. A Pretty good example can be found at
2. If you don't have control on that, you can loop threw the dataset and convert the rows into columns. Sample script as 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());
}
for(int i=0; i<dt.Rows.Count; i++)
{
dtNew.Columns[i+1].ColumnName = dt.Rows[i].ItemArray[0].ToString();
}
//Adding Row Data
for(int k=1; k<dt.Columns.Count; k++)
{
DataRow r = dtNew.NewRow();
r[0] = dt.Columns[k].ToString();
for(int j=1; j<=dt.Rows.Count; j++)
r[j] = dt.Rows[j-1][k];
dtNew.Rows.Add(r);
}
return dtNew;
}
For More info refer thread
Onunsibi-ga Jennifer Yazzie https://wakelet.com/wake/WkjquPT5tNlsBh73qVLC5
ReplyDeletedibineca