- Joined
- Jun 26, 2008
- Messages
- 1
- Reaction score
- 0
I have a Distribution list table who's members I display using a Datagrid. When I display the list of possible user to be added to the Distribution list, I use a ListBox but I want to remove the listing of any user who is already a member.
I tried doing an SQL statement that excludes any user who is already a member of this DistList, but because there are many more DistLists, my user could be a member of another DistList and therefore show up anyhow.
I then tried to Iterate through the Datagrid and exclude any names who's ID match that in the Database, but I'm still missing something again..
I tried doing an SQL statement that excludes any user who is already a member of this DistList, but because there are many more DistLists, my user could be a member of another DistList and therefore show up anyhow.
Code:
strSQL = ""
strSQL = " SELECT DISTINCT tblNames_distLists.names_id, tblNames.lname, tblNames.fname"
strSQL = strSQL & " FROM tblNames INNER JOIN"
strSQL = strSQL & " tblNames_distLists ON tblNames.names_id = tblNames_distLists.names_id"
'strSQL = strSQL & " WHERE (tblNames_distLists.distlist_id <> '" & iDistList_id & "')"
I then tried to Iterate through the Datagrid and exclude any names who's ID match that in the Database, but I'm still missing something again..
Code:
Try
If objConnection.State = ConnectionState.Closed Then
objConnection.Open()
End If
objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection)
Do While objDataReader.Read
For Each myDataGridItem In DataGridMembers.Items
Dim names_ID As Label = DirectCast(myDataGridItem.FindControl("names_ID"), Label)
If objDataReader("names_id") = names_ID.Text Then
Exit For
Else
Dim lItem As New ListItem
With lItem
.Value = objDataReader("names_id")
.Text = objDataReader("fname") & " " & objDataReader("lname")
End With
All_Users.Items.Add(lItem)
End If
Next
Loop
Catch ex As Exception
lblMessage.Text = ex.Message
Finally
objConnection.Close()