简体   繁体   English

在文本框中插入ID和返回值实体框架c#

[英]Inserting ID in Textbox And Return Values Entity Framework c#

I am inserting ID of student in the textbox and i want to return all the values in different labels. 我在文本框中插入了学生ID,并且我想在不同的标签中返回所有值。 If am using Three tables Students,Attend and Courses. 如果正在使用三张表的学生,参加和课程。 SID of student is a foreign key in Attend And cID of courses have a foreign key in Attend Table. 学生的SID在“参加”中是一个外键,而课程的cID在“参加者”表中是一个外键。 i am joining these three tables . 我要加入这三个表。

   Attend obJ = new Attend();
   Student oAd = new Student();
   oAd.sID = int.Parse(metroTextBox1.Text);

   var entryPoint = (from ep in dbContext.Attends
   join en in dbContext.Students on ep.sID equals en.sID join te 
   in dbContext.Courses on ep.cID equals te.cId
   where en.sID == oAd.sID
   select new{

      Name = en.First_Name,
      Course = te.Name,
      Presents=ep.Present,
      Absents=ep.Absent,
      });

            foreach (var iL in entryPoint) {

                metroLabel1.Text = iL.Name;
                metroLabel2.Text = iL.Course;
               metroLabel3.Text = iL.Absents.ToString();
               metroLabel4.Text = iL.Presents.ToString();

            }

the code is not giving any kind of response i want to show all though it is not giving anykind of error 该代码没有给出任何形式的响应,尽管它没有给出任何类型的错误,但我想显示全部

Student table Sid is in Attend Table
Course  table cID is in Attend Table

By joining these three tables i want to show which student has taken which course and what is the name of that course 通过连接这三个表格,我想显示哪个学生参加了哪门课程,该课程的名称是什么

by trying again and again i have found the answer how to join and get the fields of different classes from using foreach loop 通过一次又一次的尝试,我找到了如何使用foreach循环连接和获取不同类的字段的答案

        foreach (var eb in dbContext.Attends) {

            metroLabel3.Text= eb.Student.First_Name.ToString();

        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM