1

我正在尝试加入两个表并将加入结果显示到 WinForms 中的 GridView 中,但是出了点问题......

它没有给我错误消息或其他东西,请帮助!

我的代码:

var temp = teacherCmbBx.SelectedItem.ToString();

var temp2 = (from c in context.Teachers
             where temp == c.FirstName
             select c).ToList();
long num = temp2[0].ID;

var teacherGroup = (from t in context.Teachers
                    join g in context.Groups on t.ID equals g.TeacherID
                    where num == t.ID
                    select t);

teachergrpGridView.DataSource = teacherGroup;

string temp3 = (string)teachergrpGridView.Rows[rowNum].Cells[0].Value;
4

2 回答 2

1

你快到了。你只是失踪了.ToList()

var teacherGroup = (from t in context.Teachers
                    join g in context.Groups on t.ID equals g.TeacherID
                    where num == t.ID
                    select t).ToList();

teachergrpGridView.DataSource = teacherGroup;
于 2013-09-10T14:20:46.013 回答
0
 var teacherGroup = from t in context.Teachers
                                join g in context.Groups on t.ID equals g.TeacherID
                                where num == t.ID
                                select new {
                                  t.Id ,
                                  g.Name,
                                  t.xxxx 
                                 };
于 2013-09-10T14:30:36.217 回答