DataTable.Load Performance Slow, DataAdapter = Fast

I did a simple performance test using the new DataTable.Load(DataReader) method

The both of these queries return 70461 rows from SQLServer 2000 table.

Performance is as follows:

Using DataTable.Load() = 8.473 seconds
Using DataAdapter = 2.814 seconds

DataTable.Load() very slow compared to DataAdapter, why is this.

Maybe someone can spot a problem in my code:


// Using SqlDataAdapter.Fill() = 2.814 seconds (Much Faster)
String connectionString = "data source=Danielle;initial catalog=ZIPInfo;integrated security=true";
String sqlQuery = "SELECT * FROM ZIPCODES";// WHERE StateCode = 'NV'";
DataTable dt = new DataTable("Test");

using (SqlConnection oSqlConnection = new SqlConnection(connectionString))
{
oSqlConnection.Open();

using (SqlCommand sqlCommand = new SqlCommand(sqlQuery, oSqlConnection))
{
sqlCommand.CommandType = CommandType.Text;

using (SqlDataAdapter da = new SqlDataAdapter(sqlCommand))
{
da.Fill(dt);
}
}
}


// Using DataTable.Load() = 8.473 seconds (Much Slower)
String connectionString = "data source=Danielle;initial catalog=ZIPInfo;integrated security=true";
String sqlQuery = "SELECT * FROM ZIPCODES";// WHERE StateCode = 'NV'";
DataTable dt = new DataTable("Test");

using (SqlConnection oSqlConnection = new SqlConnection(connectionString))
{
oSqlConnection.Open();

using (SqlCommand sqlCommand = new SqlCommand(sqlQuery, oSqlConnection))
{
sqlCommand.CommandType = CommandType.Text;

using (SqlDataReader rdr = sqlCommand.ExecuteReader())
{
dt.Load(rdr);
}
}
}

[2171 byte] By [RussellMangel] at [2007-12-16]
# 1

Hello.... It's me again!

No Ideas?

Hmmmmmmmmm.

What does this mean?

RussellMangel at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 2
Russell,

I haven't played around with VS2005 yet, so I'm just guessing here. Your code looks ok to me, as far as I can tell.

It's my understanding that a lot of the new data stuff in VS 2005 is simply a wrapper around existing functionality to make it easier to use. I may be wrong about that, but if not, then it stands to reason that the extra layer of stuff might slow things down.

Personally, I like the DataAdapter and the .Fill() ... I don't see any reason to improve on it ... but, hey, that's probably just me. Big Smile

BonnieB at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...

.NET Development

Site Classified