Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grouping an Active Directory search

Status
Not open for further replies.

BillDoor

IS-IT--Management
Jun 28, 2004
112
GB
Hi

I'm using VB 2005 Express to create a small Directory search program four our company, to allow users to look up phone numbers etc. from Active Directory.

I've been able to search for contact details, but I would like to pull out a list of Departments and build them into a menu.

I can list the departments, but I get all of them when I just want to get 1 instance of each. If I were using a SQL DB then I would use the GROUP BY function, but I cannot find an equivalent in the DirectorySearcher object.

Can anyone suggest a way I can get a list of Departments out of Active Directory, with each Department name being listed just once?

====================
Mr Shine him diamond
 
Can't you just loop through the results and only add a new menuitem / comboboxitem when it doesn't already exist?

Regards, Ruffnekk
---
Is it true that cannibals don't eat clowns because they taste funny?
 
That was going to be my last resort, but there are a lot of user records to go through. I thought I'd ask here first to see if there was an easier way.

I have been able to use the AD provider to place the search results into a RecordSet. Does anyone know if I can query this recordset to give me what I need?

====================
Mr Shine him diamond
 
If it's an ADO RecordSet you can populate a dataset with first:

Code:
Dim myDA As OleDbDataAdapter = New OleDbDataAdapter
Dim myDS As DataSet = New DataSet

myDA.Fill(myDS, myRecordSet, "MyTable")

Then you can use an SQL statement like:

Code:
Dim myDRS As DataRow() = myDS.Tables("MyTable").Select("DISTINCT [myFieldname]","[myFieldName] ASC")

For Each myDR As DataRow In myDRS
  myCombobox.Items.Add(myDR("myFieldName"))
Next

From the top of my head, so please watch for typos/errors ;)

Regards, Ruffnekk
---
Is it true that cannibals don't eat clowns because they taste funny?
 
I'll have a look at that, thanks very much.

====================
Mr Shine him diamond
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top