检查科学复选框时。 Science将在DataGridView中显示但是当我检查Reading和Science时,这两个主题无法在DataGridView上显示。解决此问题的最佳方法(代码)是什么?提前谢谢。
`Public com As New MySql.Data.MySqlClient.MySqlCommand
Public da As New MySql.Data.MySqlClient.MySqlDataAdapter
Public dr As MySql.Data.MySqlClient.MySqlDataReader
Public dt As New DataTable
Public dt2 As New DataTable
Public ds As DataSet
Dim strSQL As String
Dim strSQL2 As String
Private Sub gbsubject_Enter(sender As Object, e As EventArgs) Handles gbsubject.Enter
Dim SDA As New MySql.Data.MySqlClient.MySqlDataAdapter
Dim dbDataSet As New DataTable
Dim bSource As New BindingSource
If cbxscience.Checked = True Then
con.Close()
con.Open()
strSQL2 = "SELECT subject_tbl.subject, lessonplan_tbl.lessontitle, kind_tbl.kind FROM kind_tbl INNER JOIN(lessonplan_tbl INNER JOIN(subject_tbl INNER JOIN skul_tbl ON subject_tbl.subjectID = skul_tbl.subjectID) ON lessonplan_tbl.lessonplanID = skul_tbl.lessonplanID) ON kind_tbl.kindID = skul_tbl.kindID WHERE subject_tbl.subject = '" & "SCIENCE" & "'"
dgvlessonplan.AutoSizeRowsMode = _
DataGridViewAutoSizeRowsMode.None
com = New MySql.Data.MySqlClient.MySqlCommand(strSQL2, con)
SDA.SelectCommand = com
SDA.Fill(dbDataSet)
bSource.DataSource = dbDataSet
dgvlessonplan.DataSource = bSource
SDA.Update(dbDataSet)
con.Close()
End If
If cbxreading.Checked And cbxscience.Checked Then
con.Close()
con.Open()
strSQL2 = "SELECT subject_tbl.subject, lessonplan_tbl.lessontitle, kind_tbl.kind FROM kind_tbl INNER JOIN(lessonplan_tbl INNER JOIN(subject_tbl INNER JOIN skul_tbl ON subject_tbl.subjectID = skul_tbl.subjectID) ON lessonplan_tbl.lessonplanID = skul_tbl.lessonplanID) ON kind_tbl.kindID = skul_tbl.kindID WHERE subject_tbl.subject = '" & "READING" & "' and subject_tbl.subject = '" & "SCIENCE" & "'"
dgvlessonplan.AutoSizeRowsMode = _
DataGridViewAutoSizeRowsMode.None
com = New MySql.Data.MySqlClient.MySqlCommand(strSQL2, con)
SDA.SelectCommand = com
SDA.Fill(dbDataSet)
bSource.DataSource = dbDataSet
dgvlessonplan.DataSource = bSource
SDA.Update(dbDataSet)
con.Close()
End If`
答案 0 :(得分:0)
您需要在OR
变量中使用AND
而不是strSQL2
。
所以,改变一下:
strSQL2 = "SELECT subject_tbl.subject, lessonplan_tbl.lessontitle, kind_tbl.kind FROM kind_tbl INNER JOIN(lessonplan_tbl INNER JOIN(subject_tbl INNER JOIN skul_tbl ON subject_tbl.subjectID = skul_tbl.subjectID) ON lessonplan_tbl.lessonplanID = skul_tbl.lessonplanID) ON kind_tbl.kindID = skul_tbl.kindID WHERE subject_tbl.subject = '" & "READING" & "' and subject_tbl.subject = '" & "SCIENCE" & "'"
到此:
strSQL2 = "SELECT subject_tbl.subject, lessonplan_tbl.lessontitle, kind_tbl.kind FROM kind_tbl INNER JOIN(lessonplan_tbl INNER JOIN(subject_tbl INNER JOIN skul_tbl ON subject_tbl.subjectID = skul_tbl.subjectID) ON lessonplan_tbl.lessonplanID = skul_tbl.lessonplanID) ON kind_tbl.kindID = skul_tbl.kindID WHERE subject_tbl.subject = 'READING' OR subject_tbl.subject = 'SCIENCE'"