即使我们传递了一些东西,DataGridView内容也是null

时间:2015-01-09 11:24:00

标签: c#

我有以下代码

DataGridView dataGridViewAR = new DataGridView();
dataGridViewAR.DataSource = db.GetYearlyReport(2015); // this one returns an IEnumerable
string temp = dataGridViewAR.Rows[0].Cells[0].Value.ToString();

在调试过程中,当我将鼠标悬停在dataGridViewAR.DataSource上时,它显示有52个内容。

enter image description here

当我悬停dataGridViewAR.DataSource的内容时,它会显示内容

enter image description here

但是当我尝试访问该datagridview的内容时,它显示没有内容..行计数为0.为什么会这样?

enter image description here

enter image description here

这是db.GetYearlyReport代码段

 public IEnumerable GetYearlyReport(int year)
        {
            db = new PACUCOADB5Entities();

            var Report = (from ap in db.Accreditor_Program
                          orderby ap.Program.Visit.Starting_Date ascending
                          where
                           ap.Program.Visit.Starting_Date.Value.Year == year
                          select new
                          {
                              ap.Program.Visit.Starting_Date,
                              ap.Program.Visit.Ending_Date,
                              ap.Program.Visit.School.Name,
                              ap.Program.Type_of_Visit,
                              ap.Program.Educational_Level,
                              ap.Program.RA_Number,
                              ap.Program.Requested_Program,
                              ap.Accreditor.Title,
                              ap.Accreditor.Surname,
                              ap.Accreditor.Given_Name,
                              ap.Accreditor.Middle_Initial,
                              ap.Assigned_Area

                          }).ToList();

            return Report;
        }

谢谢!

0 个答案:

没有答案