Reputation: 41
Ihave to add rows in:
dtbl = new DataTable();
dtbl.Columns.Add("Ad.No", typeof(String)); alignment[0] = 'C'; width[1] = 40;
dtbl.Columns.Add("AdmissionDate", typeof(String)); alignment[1] = 'C'; width[2] = 50;
dtbl.Columns.Add("Name", typeof(String)); alignment[2] = 'L'; width[3] = 100;
dtbl.Columns.Add("Class", typeof(String)); alignment[3] = 'C'; width[5] = 40;
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++)
{
dtbl.Columns.Add(Common.CommonUtility.GetShortMonthName(j)+" "+k, typeof(String)); alignment[4] = 'C'; width[5] = 40;
}
}
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++)
{
// dtbl.Rows.Add(dt[j]=std.value);
// foreach (var r in std.value){
dtbl.Rows.Add(dt["Ad.No"] = std.AdmissionNo, dt["AdmissionDate"] = Convert.ToDateTime(std.date.ToString()).ToString("dd/MM/yyyy"), dt["Class"] = std.Class, dt["Name"] = std.StudentName,dt[j]=std.value);
}
}
I have to add rows in columns cell like p A p A
Upvotes: 4
Views: 95
Reputation: 9490
When creating the columns, the column name could contain also the year to be unique:
private GetColumnName(int year, int month, int day)
{
return year.ToString() + " " + Common.CommonUtility.GetShortMonthName(month) + " " + day;
}
If std
contains the value for one date, it would help if the std
record provided also this date (or three properties year, month, day).
Then a list of std
loaded from DB could be grouped by row identifier (is it the Ad.No?) and each group processed to fill one row:
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);
}
Upvotes: 1