我要添加行:
objectId
我必须在列单元格中添加行,例如p A p A
答案 0 :(得分:1)
创建列时,列名称也可以包含唯一的年份:
private GetColumnName(int year, int month, int day)
{
return year.ToString() + " " + Common.CommonUtility.GetShortMonthName(month) + " " + day;
}
如果std
包含一个日期的值,那么如果std
记录也提供此日期(或三个属性年,月,日),则会有所帮助。
然后,可以按行标识符(是Ad.No?)对从DB加载的std
列表进行分组,并处理每个组以填充一行:
var stdList = ... select from DB;
var stdGroups = stdList.GroupBy(x => x.AdmissionNo);
foreach(var group in stdGroups)
{
var stds = group.ToList();
var row = dtbl.NewRow(); // a new row of untyped data table
row["Ad.No"] = stds.First().AdmissionNo;
// ...set also the other properties
for (int i = model.FromYear; i <= model.ToYear; i++)
{
for (int j = model.FromMonth; j <= model.ToMonth; j++)
{
for (int k = model.FromDay; k <= model.ToDay; k++)
{
var std = stds.Single(x => x.Year == i && x.Month == j && x.Day == k);
row[GetColumnName(i,j,k)] = std.value;
}
}
}
dtbl.Rows.Add(row);
}