Assuming the DataSet is hurting performance, you'll want to add this code
ArrayList userList = theDirectory.getUsers();
// Starts bulk loading
// Defers indexing and constraint checking
// till EndLoadData();
tblUsers.Users.BeginLoadData();
if (userList != null)
{
foreach (UserDirectoryObject user in userList)
{
DataRow drUser = tblUsers.NewRow();
drUser["lastName"] = user.lastName;
drUser["firstName"] = user.firstName;
/* etc */
tblUsers.Rows.Add(drUser);
}
}
// Ends the bulk loading
tblUsers.Users.EndLoadData();
tblUsers.DefaultView.Sort = "lastName";
return tblUsers.DefaultView
HTH
Thanks,
Shawn Wildermuth
[EMAIL PROTECTED]
Author of Pragmatic ADO.NET
http://adoguy.com/book
http://ONDotnet.com
Microsoft .NET MVP
> -----Original Message-----
> From: Moderated discussion of advanced .NET topics.
> [mailto:[EMAIL PROTECTED] On Behalf Of Dirk Reuss
> Sent: Saturday, January 17, 2004 6:25 AM
> To: [EMAIL PROTECTED]
> Subject: [ADVANCED-DOTNET] AW: [ADVANCED-DOTNET] Fastest way
> to add contents of ArrayList to a DataTable
>
> HI
>
> Disconnect the DataGrid before you add the new rows. If the
> DataGrid is connected via DataSource, to default view (or
> others) applies filter and sorting for each added row
>
> Dirk
>
> -----Urspr�ngliche Nachricht-----
> Von: Scott A. Lawrence [mailto:[EMAIL PROTECTED]
> Gesendet: Dienstag, 6. Januar 2004 20:08
> An: [EMAIL PROTECTED]
> Betreff: [ADVANCED-DOTNET] Fastest way to add contents of
> ArrayList to a DataTable
>
>
> I'm writing a user profile tool that manipulates information
> in an LDAP server. I'm using an abstraction layer that talks
> directly to the server (written by another developer). The
> function of the abstraction layer that returns a list of all
> the users in LDAP returns an ArrayList. For easier filtering
> and sorting of this data, I build a DataTable in code,
> returning its default view so it can be bound to a DataGrid.
>
> The app currently takes between 15-20 seconds to load
> approximately 800 users from the LDAP source into memory,
> cache the user information, and display the page (DataGrid
> displays 20 users per page). The vast majority of that time
> (13-18 seconds) is consumed by the foreach loop that puts
> each ArrayList element into the
>
> The code in question looks like the following:
>
> ArrayList userList = theDirectory.getUsers();
>
> if (userList != null)
> {
> foreach (UserDirectoryObject user in userList)
> {
> DataRow drUser = tblUsers.NewRow();
> drUser["lastName"] = user.lastName;
> drUser["firstName"] = user.firstName;
> /* etc */
> tblUsers.Rows.Add(drUser);
> }
> }
>
> tblUsers.DefaultView.Sort = "lastName";
> return tblUsers.DefaultView
>
>
> Any suggestions about how to increase the speed of this would
> be greatly appreciated.
>
> Thanks!
>
> ===================================
> This list is hosted by DevelopMentor� http://www.develop.com
> Some .NET courses you may be interested in:
>
> NEW! Guerrilla ASP.NET, 26 Jan 2004, in Los Angeles
> http://www.develop.com/courses/gaspdotnetls
>
> View archives and manage your subscription(s) at
> http://discuss.develop.com
>
> ===================================
> This list is hosted by DevelopMentor� http://www.develop.com
> Some .NET courses you may be interested in:
>
> NEW! Guerrilla ASP.NET, 26 Jan 2004, in Los Angeles
> http://www.develop.com/courses/gaspdotnetls
>
> View archives and manage your subscription(s) at
> http://discuss.develop.com
>
===================================
This list is hosted by DevelopMentor� http://www.develop.com
Some .NET courses you may be interested in:
NEW! Guerrilla ASP.NET, 26 Jan 2004, in Los Angeles
http://www.develop.com/courses/gaspdotnetls
View archives and manage your subscription(s) at http://discuss.develop.com