在我的项目中,我编写了一个程序来显示已加入特定类的所有成员。将数据添加到我的列表框中时,如果返回了2个结果,则这两个相同的结果将多次添加到列表框中,我只希望将结果添加一次。有没有人知道为什么我的记录被添加了太多次?
Private Sub DisplayMembersOnClass(CurrentClassID As Integer)
If CurrentClassID <> -1 Then
If Dbconnect() Then
Dim SQLCMD As New OleDbCommand
With SQLCMD
.Connection = cn
.CommandText = "Select * " &
"From MembersClass,Class, Members " &
"Where MembersClass.ClassID = @CurrentClassID and Members.MemberID = MembersClass.MemberID"
.Parameters.AddWithValue("@CurrentClassID", CurrentClassID)
End With
Dim rs As OleDbDataReader = SQLCMD.ExecuteReader
While rs.Read
Dim firstname As String = rs("FirstName")
Dim secondname As String = rs("SecondName")
Dim MemberName = (firstname) & " " & (secondname)
Dim DisplayValue As String = (MemberName) & " " & rs("Members.MemberID")
Dim classitem As New ListBoxData(DisplayValue, & "ID - " rs("Class.ClassID"))
ListBoxMembersOnClass.Items.Add(classitem)
End While
rs.Close()
End If
End If
End Sub