【发布时间】:2019-03-17 12:03:19
【问题描述】:
我有
表student、student_subject和subject_bsit
"student"
-----------------------
|studentID | FullName |
-----------------------
|1234 | John |
|1235 | Michael |
|1236 | Bryce |
"subject_bsit"
-----------------------------------
|subject_id| subject_name |grade |
-----------------------------------
| 1 | Programming | 3 |
| 2 | Networking | 2.5 |
| 3 | Algorithm | 1.75|
| 4 | Physical Educ | 2 |
This is the Junction table to connect the
two now.
"student_subject"
----------------------------
| student_id | subject_id |
----------------------------
| 1235 | 1 |
| 1235 | 2 |
| 1235 | 3 |
| 1234 | 1 |
如您所见,表 ID 1235 是 michael 他有三个三个主题,subject_id 1,2 和 3。我想要做的是在文本框中显示 michael 的所有主题名称和成绩,而不是在数据网格视图中.
到目前为止,我仍然无法将其输出到文本框。这是我的示例查询
sql = "SELECT subject_name " & _
" FROM student_subject " & _
" INNER JOIN subject_bsit ON subject_bsit.subject_id = student_subject.sub_id" & _
" where student_subject.student_id='" & Txtbox.Text & "'"
最后一个查询中的 Txtbox.text 是用户输入 ID 号的地方。
这是我在文本框中显示数据的代码。我对如何在文本框上循环并将其显示在每个文本框上没有任何想法或方法。
cmd = New MySqlCommand(sql, myconn)
dr = cmd.ExecuteReader
While dr.Read
TextBox1.Text = dr.Item("subject_name").ToString
TextBox2.Text = dr.Item("subject_name").ToString
End While
这是我想要实现的示例用户界面。非常感谢。
【问题讨论】:
-
欢迎来到 Stack Overflow。在这里提问无需说“对不起”:欢迎初学者!你的问题写得很好。
-
我会更改您的数据库架构。成绩不属于主题表。应该有一个包含学生 ID、学科 ID 和成绩的表格。
-
@Mary 嗨。是的,我现在遇到了麻烦,因为我无法更新连接表中的成绩。我是否应该为它创建一个新主题,我昨天正在做,然后我再次访问这里,然后阅读您的回复,我应该制作另一个连接表吗? student_grade 包含 student_id subject_id 和成绩?
-
设置成绩表的主键。由 studentID 和 subjectID 组成的两列 PK 将起作用。
标签: mysql sql database vb.net phpmyadmin