我有两个表名为“ studentBio ”和“主题”。下面给出了两个表的字段(带有一些值):在表单上我有这样的东西: 我在 checkedlistbox1 中的 AND 以A + B + C的形式显示相应的主题。从用户检索后,将根据“+”进行拆分,并一次性添加到主题表中。
studentBio 表的字段如下: WHERE (RollNo,RegYear,program和faculty结合使复合主键):
RollNo RegYear stuName program faculty phoneNuber Address
1 2010 John Intermediate Pre-Engineering 343483834 London
2 2011 Leonard Intermediate Pre-Medical 454545445 NewYork
3 2012 Henry Graduation B.A 565656565 Oslo
科目表的相似字段如下: WHERE (RollNo,RegYear,program和faculty结合使用复合 主键):
RollNo RegYear program faculty subjectName
1 2010 Intermediate Pre-Engineering A
1 2010 Intermediate Pre-Engineering B
1 2010 Intermediate Pre-Engineering C
2 2011 Intermediate Pre-Medical D
2 2011 Intermediate Pre-Medical E
2 2011 Intermediate Pre-Medical F
等等。现在让我们来讨论问题。我正在做的是两个表中的更新(教师和计划)和主题表中的 subjectN 。到目前为止我所做的是我只更新了 studentBio 表,这很简单,但我无法理解为什么我可以构建更新查询以更新主题表?有人可以帮我构建查询吗?
答案 0 :(得分:1)
如果我理解得很好,请尝试重新构建您的查询版本:
string update_Personal = "UPDATE studentBio INNER JOIN subjects ON studentBio.RollNo = subjects.RollNo AND studentBio.RegYear = subjects.RegYear AND studentBio.program = subjects.program AND studentBio.faculty = subjects.faculty SET studentBio.program = ProgramU, studentBio.faculty = FacultyU, subjects.subjectName = SubjectNameU WHERE studentBio.RollNo = " + Convert.ToInt32(this.rollNumber7_combo.SelectedItem.ToString()) + " AND studentBio.RegYear = " + Convert.ToInt32(this.comboBox3.SelectedItem.ToString()) + " AND studentBio.program = '" + this.comboBox1.SelectedItem.ToString() + "' AND studentBio.faculty = '" + this.comboBox2.SelectedItem.ToString() + "'";
我已添加以下部分以使其更新subjects
表格:
studentBio INNER JOIN subjects ON studentBio.RollNo = subjects.RollNo AND studentBio.RegYear = subjects.RegYear AND studentBio.program = subjects.program AND studentBio.faculty = subjects.faculty
- 此部分加入subjects
表,使其更新成为可能
, subjects.subjectName = SubjectNameU
- 主题表中SET
块更新subjectName列中的片段
WHERE studentBio.RollNo = " + Convert.ToInt32(this.rollNumber7_combo.SelectedItem.ToString()) + " AND studentBio.RegYear = " + Convert.ToInt32(this.comboBox3.SelectedItem.ToString()) + " AND studentBio.program = '" + this.comboBox1.SelectedItem.ToString() + "' AND studentBio.faculty = '" + this.comboBox2.SelectedItem.ToString() + "'"
- 最后一部分是WHERE
块,其中前缀studentBio.
被添加到每个键列,以精确到应该应用过滤的表(因为两者都是表格具有相同的键列名称)
我希望它能以某种方式帮助你。