Problems displaying data from OleDb Provider

M

Mick Heywood

Hi there,

I am trying to display information from Active Directory using a DataGrid.
Now, I know MS have put out the System.DirectoryServices classes to make this
easy. But if you just want to query and display, it seems an easier path is
to use the AdsDsoObject provider with OleDb, and get back a DataTable, pour
into a DataView, bind to the DataGrid, voila! At least, that's the theory.
The main driver is that trying to bind a SearchResultCollection to a DataGrid
doesn't yield very satisfactory results, and that's the only useful class in
the DirectoryServices namespace that implements ICollection and IEnumerable.

The problem is, if I manually construct a DataTable with dummy data, pour
into a DataView, bind to DataGrid and display then I see exactly what I would
expect.
If I setup an OleDbDataAdapter, query the AD, fill a DataSet and serialize
to XML I see what I would expect.
If I setup an OleDbDataAdapter, query the AD, fill a DataTable, pour into a
DataView, bind to the DataGrid and display, I get:
System.Web.HttpException: DataGrid with id '' could not automatically
generate any columns from the selected data source

Here is the source for Page_Load that generates the last result:

string ldapString =
"<LDAP://DC=acme,DC=com>;(&(objectClass=user)(objectCategory=person));cn,distinguishedName;subtree";
string connstr = "Provider=ADsDSOObject;User
ID=acme\\Administrator;Password=notthispassword";
OleDbConnection conn = new OleDbConnection(connstr);
OleDbDataAdapter da = new OleDbDataAdapter(ldapString, conn);
DataTable dt = new DataTable("Table1");
da.Fill(dt);
DataView dv = new DataView(dt);
dg1.DataSource = dv;
dg1.DataBind();

Now, I'm fairly new to all this, but I've spent a good couple of days
butting up against this one. The only checking I haven't really done is
using OleDb with a different provider and seeing if it is a general problem.
The main reason I haven't done that is that I can see the data there if I use
an alternate means of accessing it! So, any ideas?

MTIA,

Mick Heywood
 

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

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,234
Latest member
SkyeWeems

Latest Threads

Top