Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- visualstudio 관리자권한
- RichEditControl
- CustomDrawColumnHeader
- C# WndProc
- ColumnHead MultiLine
- C# 빌드이벤트
- 밀면
- C# Devexpress CheckListBoxControl word wrap
- C# 0x8001010d
- C# 컬럼비교
- drawgrid
- Row Indicator
- RichEditControl Bold
- Delphi
- C# linq pivot
- C# column
- C# 매크로
- C#
- DataTable ReadOnly
- devexpress grid
- 델파이
- mssql 문자열 합치기
- C# SendMessage
- C# Devexpress CheckListBoxControl 줄 바꿈
- 밀고
- C# DataTable linq
- C# Devexpress
- C# build
- delphi JSON
- 해운대밀면
Archives
- Today
- Total
개발자의 사투
C# DataTatable pivot Linq 본문
DataTable Pivot(DataTable dt, DataColumn pivotColumn, DataColumn pivotValue)
{
if (dt.isNullOrEmpty() || dt.Rows.Count == 0)
return null;
// find primary key columns
//(i.e. everything but pivot column and pivot value)
DataTable temp = dt.Copy();
temp.Columns.Remove(pivotColumn.ColumnName);
temp.Columns.Remove(pivotValue.ColumnName);
string[] pkColumnNames = temp.Columns.Cast<DataColumn>()
.Select(c => c.ColumnName)
.ToArray();
// prep results table
DataTable result = temp.DefaultView.ToTable(true, pkColumnNames).Copy();
result.PrimaryKey = result.Columns.Cast<DataColumn>().ToArray();
dt.AsEnumerable()
.Select(r => r[pivotColumn.ColumnName].ToString())
.Distinct().ToList()
.ForEach(c => result.Columns.Add(c, pivotColumn.DataType));
// load it
foreach (DataRow row in dt.Rows)
{
// find row to update
DataRow aggRow = result.Rows.Find(
pkColumnNames
.Select(c => row[c])
.ToArray());
// the aggregate used here is LATEST
// adjust the next line if you want (SUM, MAX, etc...)
aggRow[row[pivotColumn.ColumnName].ToString()] = row[pivotValue.ColumnName];
}
return result;
}
'컴방 > C#' 카테고리의 다른 글
C# 재시도횟수(10)을 초과하여 작업을 수행하지 못했습니다/파일은 다른 프로세스에서 사용중이므로 프로세스에서 엑세스할 수 없습니다. (0) | 2021.03.12 |
---|---|
C# Devexpress CheckListBoxControl 내용 줄바꿈 (0) | 2020.09.16 |
visualstudio 관리자 권한 자동 실행 (0) | 2020.08.21 |
C# DevExpress RichEditControl 특정 행 폰트변경 (0) | 2020.08.12 |
C# WndProc 사용 시 0x8001010d 오류 해결 (1) | 2020.07.10 |
Comments