繁体   English   中英

从数据集中检索数据

[英]Retrieve data from dataset

SqlDataAdapter da = new SqlDataAdapter("Select StudentID,StudentName from StudentMaster where StudentID = '" + start + "'", conn);              
DataSet ds = new DataSet();
da.Fill(ds,"StudentMaster");
SqlDataAdapter db = new SqlDataAdapter("Select Registration_No from Candidate_Registration where StudentID='" + start + "'", conn);
db.Fill(ds, "Candidate_Registration");

这里的“开始”是以前形式即form2的文本框的文本框值。 我想从StudentMaster =开始的StudentMaster中获取StudentName和StudentID。 该表名为“ StudentMaster”。 用StudentMaster填充数据集。 然后,我想从Candidate_Registration那里获取Student_ = start的Registration_No。 该表名为“ Candidate_Registration”。 用Candidate_Registration填充数据集。 现在根据获取的“ Registration_No”,我想从“ Registered_Courses”中获取“ CourseID”。 但是,问题是,如何访问获取的“ Registration_No”,即如何将其放入以下查询中:如果我可以将获取的Registration_No放入名为“ reg_no”的变量中,则“从Registered_Courses中选择CourseID,其中Registration_No =“ + reg_no;

为了获得更多的理解,我提到了表格和关系。

StudentMaster
-------------
StudentID Primary key,
StudentName

Candidate_Registration
----------------------
Registration_No Foreign key,
ExamID Foreign key,
StudentID Foreign key,
Seat_No,
Primary key(Registration_No,ExamID)

Registered_Courses
------------------
Registration_No Primary key,
ExamID Foreign key,
CourseID Foreign key,

Course_Master
-------------
CourseID Primary key,
Course_Name,
Description

即最后我想获得特定学生ID的Course_Name。

谁能帮我一下。 提前致谢!

试试这个查询:

Select StudentMaster.StudentId, Course_Master.Course_Name from StudentMaster 
INNER JOIN Candidate_Registration 
ON Candidate_Registration.StudentId = StudentMaster.StudentId 
INNER JOIN Registered_Courses 
ON Registered_Courses.Registration_No = Candidate_Registration.Registration_No AND Registered_Courses.ExamID = Candidate_Registration.ExamID 
INNER JOIN Course_Master 
ON Course_Master.CourseID = Registered_Courses.CourseID
WHERE StudentMaster.StudentId = @MyId

将@MyId替换为您的Id参数,它会为您提供StudentId的所有课程名称。

暂无
暂无

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

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