所以我将代码放在下一个按钮中,当我运行它时,它会正确显示第一个,因为它在表单加载中,但是当我单击下一个按钮时,它会跳过并显示后面的记录。
这是代码:
Private Sub EnrollmentForm_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'PROJECT22DataSet.Student' table. You can move, or remove it, as needed.
Me.StudentTableAdapter.Fill(Me.PROJECT22DataSet.Student)
Try
Dim Query As String
Dim DataReader As OdbcDataReader
Dim Command As New OdbcCommand
dc.Open()
Query = "SELECT Classname FROM Enroll WHERE STUNUM = (SELECT SID FROM Student WHERE SID = ?);"
'"SELECT FROM EVENT WHERE ORG_ID = ?"
'Command.Paramenters.AddWithValue("ORG_ID", Combox.
Command.Connection = dc
Command.CommandText = Query
'Data comes from the dropbox box, then performs the subquery to gain the org id. Then queries all the events for that org_id
Command.Parameters.AddWithValue("SID", SIDTextBox.Text.ToString)
DataReader = Command.ExecuteReader()
ListBoxClassNames.Items.Clear()
While DataReader.Read()
ListBoxClassNames.Items.Add(DataReader("Classname"))
' Label_description.Text = (DataReader("Event_Description"))
End While
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
dc.Close()
End Try
End Sub