Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在Linq中联接两个表并显示联接到数据GridView?_C#_Linq_Gridview - Fatal编程技术网

C# 如何在Linq中联接两个表并显示联接到数据GridView?

C# 如何在Linq中联接两个表并显示联接到数据GridView?,c#,linq,gridview,C#,Linq,Gridview,我正在尝试连接两个表,并在WinForms中将连接结果显示到GridView中,但出现了一些问题 它没有给我错误信息或什么,请帮助 我的代码: var temp = teacherCmbBx.SelectedItem.ToString(); var temp2 = (from c in context.Teachers where temp == c.FirstName select c).ToList(); long num = temp2

我正在尝试连接两个表,并在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;

你就快到了。您只是缺少了
.ToList()


你就快到了。您只是缺少了
.ToList()


你不需要在事后调用DataBind()吗?@CheGueVerra-Its
WinForms
我认为它不是必需的(我不确定)你不需要在事后调用DataBind()吗?@CheGueVerra-Its
WinForms
我认为它不是必需的(我不确定)
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;
 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 
                                 };