从数据集中检索数据

发布于 2024-10-08 15:33:31 字数 1438 浏览 0 评论 0原文

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");

这里“start”是先前表单(即form2)中文本框的文本框值。 我想从 StudentMaster 获取 StudentName 和 StudentID,其中 StudentID = start。 该表名为“StudentMaster”。 使用 StudentMaster 填充数据集。 然后我想从 Candidate_Registration 获取 Registration_No,其中 StudentID=start。 该表名为“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

即最后我想获取特定 StudentID 的 Course_Name。

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

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");

Here 'start' is a textbox value of a textbox in previous form i.e form2.
I want to fetch StudentName and StudentID from StudentMaster where StudentID = start.
The table is named 'StudentMaster'.
Fill the dataset with StudentMaster.
Then I want to fetch Registration_No from Candidate_Registration where StudentID=start.
The table is named 'Candidate_Registration'.
Fill the dataset with Candidate_Registration.
Now according to the 'Registration_No' that is fetched, I want to fetch 'CourseID' from 'Registered_Courses'.
But, the problem is, how to access the fetched 'Registration_No' i.e. how to put it in the following query:
if I can take the fetched Registration_No into a variable named 'reg_no' then,
"Select CourseID from Registered_Courses where Registration_No="+ reg_no;

For more understanding I mention the tables and the relationships....

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

i.e. finally I want to get the Course_Name for a particular StudentID.

Can anyone please help me out. Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

勿忘心安 2024-10-15 15:33:31

尝试以下查询:

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 的所有 CourseNames。

Try this query :

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

Replace @MyId with your Id parameter and it gives you all the CourseNames for a StudentId.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文