从数据集中检索数据
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试以下查询:
将 @MyId 替换为您的 Id 参数,它会为您提供 StudentId 的所有 CourseNames。
Try this query :
Replace @MyId with your Id parameter and it gives you all the CourseNames for a StudentId.