DataSet and SearchResultCollection

G

Guest

Hello !

I want to know if there are an easy way to put a SearchResultCollection
(resulting of a query on Active Directory) into a DataSet ?
Thanks;
 
S

Sahil Malik [MVP]

Well, it wouldn't be too hard to simply create datatables and load data rows
into it using a little loop - the code should be less than 1 page.
 
G

Guest

I found an example with 3 foreach loop to do waht you say.
But I also found this
(http://216.239.59.104/search?q=cach...1.doc+searchresultcollection+to+dataset&hl=fr):
using System;

using System.Collections;

using System.Data;

using System.Data.OleDb;


class ADSql

{

static void Main(string[] args)

{

//set the OLEDB provider for Active Directory

OleDbConnection oledb = new
OleDbConnection("Provider=ADsDSOObject;");

oledb.Open();


//set attribute description list

string searchAttrs = "distinguishedName, objectCategory";


//set an ADsPath for the search base

string searchBase = "'LDAP://DC=isqre,DC=net'";


//set filter

string searchFilter = "objectClass='user'";


//build SQL query string

string searchQuery = "SELECT " + searchAttrs + " FROM " +
searchBase + " WHERE " + searchFilter;


OleDbDataAdapter oleDA = new OleDbDataAdapter(searchQuery,
oledb);


//object that will cache the data retrieved from AD

DataSet oleDS = new DataSet();


//retrieve data from AD

oleDA.Fill(oleDS,"obj");

oledb.Dispose();

oleDA.Dispose();

foreach (DataRow r in oleDS.Tables["obj"].Rows)

{ //process the result

Console.WriteLine("-->");

for (int i = 0; i < r.ItemArray.Length; i++)

Console.WriteLine(" {0}",r.ItemArray.ToString());

}

oleDS.Dispose();

}

}

What do you think of this solution ?
What about performance ?
 
S

Sahil Malik [MVP]

Thank you Ryo .. that will do just great :)


--

- Sahil Malik [MVP]
ADO.NET 2.0 book -
http://codebetter.com/blogs/sahil.malik/archive/2005/05/13/63199.aspx
----------------------------------------------------------------------------

Ryo said:
I found an example with 3 foreach loop to do waht you say.
But I also found this
(http://216.239.59.104/search?q=cach...1.doc+searchresultcollection+to+dataset&hl=fr):
using System;

using System.Collections;

using System.Data;

using System.Data.OleDb;


class ADSql

{

static void Main(string[] args)

{

//set the OLEDB provider for Active Directory

OleDbConnection oledb = new
OleDbConnection("Provider=ADsDSOObject;");

oledb.Open();


//set attribute description list

string searchAttrs = "distinguishedName, objectCategory";


//set an ADsPath for the search base

string searchBase = "'LDAP://DC=isqre,DC=net'";


//set filter

string searchFilter = "objectClass='user'";


//build SQL query string

string searchQuery = "SELECT " + searchAttrs + " FROM " +
searchBase + " WHERE " + searchFilter;


OleDbDataAdapter oleDA = new OleDbDataAdapter(searchQuery,
oledb);


//object that will cache the data retrieved from AD

DataSet oleDS = new DataSet();


//retrieve data from AD

oleDA.Fill(oleDS,"obj");

oledb.Dispose();

oleDA.Dispose();

foreach (DataRow r in oleDS.Tables["obj"].Rows)

{ //process the result

Console.WriteLine("-->");

for (int i = 0; i < r.ItemArray.Length; i++)

Console.WriteLine("
{0}",r.ItemArray.ToString());

}

oleDS.Dispose();

}

}

What do you think of this solution ?
What about performance ?

Sahil Malik said:
Well, it wouldn't be too hard to simply create datatables and load data
rows
into it using a little loop - the code should be less than 1 page.

--

- Sahil Malik [MVP]
ADO.NET 2.0 book -
http://codebetter.com/blogs/sahil.malik/archive/2005/05/13/63199.aspx
 
G

Guest

Hum, that's not so great...
Perhaps I'm bad with Active Directory but I can't found how to list all user
from it....


Sahil Malik said:
Thank you Ryo .. that will do just great :)


--

- Sahil Malik [MVP]
ADO.NET 2.0 book -
http://codebetter.com/blogs/sahil.malik/archive/2005/05/13/63199.aspx
----------------------------------------------------------------------------

Ryo said:
I found an example with 3 foreach loop to do waht you say.
But I also found this
(http://216.239.59.104/search?q=cach...1.doc+searchresultcollection+to+dataset&hl=fr):
using System;

using System.Collections;

using System.Data;

using System.Data.OleDb;


class ADSql

{

static void Main(string[] args)

{

//set the OLEDB provider for Active Directory

OleDbConnection oledb = new
OleDbConnection("Provider=ADsDSOObject;");

oledb.Open();


//set attribute description list

string searchAttrs = "distinguishedName, objectCategory";


//set an ADsPath for the search base

string searchBase = "'LDAP://DC=isqre,DC=net'";


//set filter

string searchFilter = "objectClass='user'";


//build SQL query string

string searchQuery = "SELECT " + searchAttrs + " FROM " +
searchBase + " WHERE " + searchFilter;


OleDbDataAdapter oleDA = new OleDbDataAdapter(searchQuery,
oledb);


//object that will cache the data retrieved from AD

DataSet oleDS = new DataSet();


//retrieve data from AD

oleDA.Fill(oleDS,"obj");

oledb.Dispose();

oleDA.Dispose();

foreach (DataRow r in oleDS.Tables["obj"].Rows)

{ //process the result

Console.WriteLine("-->");

for (int i = 0; i < r.ItemArray.Length; i++)

Console.WriteLine("
{0}",r.ItemArray.ToString());

}

oleDS.Dispose();

}

}

What do you think of this solution ?
What about performance ?

Sahil Malik said:
Well, it wouldn't be too hard to simply create datatables and load data
rows
into it using a little loop - the code should be less than 1 page.

--

- Sahil Malik [MVP]
ADO.NET 2.0 book -
http://codebetter.com/blogs/sahil.malik/archive/2005/05/13/63199.aspx
-------------------------------------------------------------------------------------------

Hello !

I want to know if there are an easy way to put a SearchResultCollection
(resulting of a query on Active Directory) into a DataSet ?
Thanks;

 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top