**:
/// /// datatable行轉列
///
/// 源datatable
/// 需要裝置的列
/// 資料列
/// 返回訊息
///
public static datatable rowtocolumn(datatable sourcedt, string rowname, string datacolumn, out string msg)
//獲取指定列資料並去除重複項
listcolnames = sourcedt.asenumerable().select(t => t.field(rowname)).distinct().tolist();
if (colnames == null || colnames.count == 0)
listsourcecols = new list();
datatable newdt = new datatable();
foreach (datacolumn col in sourcedt.columns)
//int colcount = newdt.columns.count;
//新增轉列後的列名稱
foreach (var col in colnames)
//進行資料轉換
foreach (datarow row in sourcedt.rows)
= ''";
}var newdtrow = newdt.select(selectstr);
if (newdtrow.length == 0)
//填充轉置後的資料
newrow[convert.tostring(row[rowname])] = row[datacolumn];
newdt.rows.add(newrow);
}else
}msg = "";
return newdt;
}catch (exception ex)
}
資料行列轉換
public static void main displaytable dt console.writeline r n 進行行列轉換 r n displaytable columntorow dt,0 console.readline public static datatable column...
C 中DataTable實現行列轉換的方法
protected void page load object sender,eventargs e 建立datatable protected datatable createdt tbldatas.rows.add new object tbldatas.rows.add new object ...
mysql行列轉換 mysql行列轉換
1.一維轉二維 上圖為成績表中資料,現希望將資料轉換為下圖。靜態 轉化為二維表後的列名及列數是確定不變的,本例中即course只有數學 語文 英語這三門課。select s name,max if course 數學 score,0 as 數學,max if course 語文 score,0 as...