Problems displaying data from OleDb Provider

Discussion in 'ASP .Net Datagrid Control' started by Mick Heywood, Nov 29, 2004.

  1. Mick Heywood

    Mick Heywood Guest

    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
    Mick Heywood, Nov 29, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian Henry

    Data type question for OLEdb data types

    Brian Henry, Oct 4, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    593
  2. Martin
    Replies:
    2
    Views:
    4,066
    Martin
    Mar 16, 2005
  3. Replies:
    0
    Views:
    738
  4. YK
    Replies:
    0
    Views:
    147
  5. YK
    Replies:
    0
    Views:
    152
Loading...

Share This Page