var qs6 = from p in db.Students
where p.SubjectID == txtSubID.Text.Trim() && p.Section == txtSec.Text.Trim()
select p.StudentID;
var student = from s in db.StudentTimeTables
where s.DateExam == txtDateExam.Text.Trim()
select s.StudentID;
foreach (var c in qs6)
{
foreach (var d in student)
{
if (Convert.ToInt32(c) == Convert.ToInt32(d))
{
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("id"));
DataRow dr = dt.NewRow();
dr["id"] = d;
dt.Rows.Add(dr);
}
}
}
ก็คุณไป New มันใน Loop ครับ มันเลยได้ค่าสุดท้ายครับ
Code (C#)
var qs6 = from p in db.Students
where p.SubjectID == txtSubID.Text.Trim() && p.Section == txtSec.Text.Trim()
select p.StudentID;
var student = from s in db.StudentTimeTables
where s.DateExam == txtDateExam.Text.Trim()
select s.StudentID;
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("id"));
foreach (var c in qs6)
{
foreach (var d in student)
{
if (Convert.ToInt32(c) == Convert.ToInt32(d))
{
DataRow dr = dt.NewRow();
dr["id"] = d;
dt.Rows.Add(dr);
}
}
}