What is the fastest way to load a Typed DataSet?

You might answer: "Just call the Fill method on a SqlDataAdapter"

Typed DataSet - Fill (Fast):

   // Create a typed DataSet
   TypedDataSetProject.CustomersDataSet customersDataSet 
                       = new TypedDataSetProject.CustomersDataSet();

   // Fill the typed DataSet's Customer DataTable
   this.sqlDataAdapter1.Fill(customersDataSet.Customers);

But there is a faster way!!!  The trick is to turn off notifications,
index maintenance, and constraints while loading the data.   

Typed DataSet - BeginLoadData, Fill (Faster - for large data sets):

   // Create the Typed DataSet
   TypedDataSetProject.CustomersDataSet customersDataSet 
                       = new TypedDataSetProject.CustomersDataSet();

   // Turn off the DataTable's notifications, index maintenance, and constraints 
   customersDataSet.Customers.BeginLoadData();

   // Fill the Typed DataSet's Customer DataTable
   this.sqlDataAdapter1.Fill(customersDataSet.Customers);

   // Turn back on notifications, index maintenance, and constraints 
   customersDataSet.Customers.EndLoadData();
 

Untyped DataSet - Fill only (Fastest)

// Fill the typed DataSet's Customer DataTable

DataSet ds = new DataSet();
this.sqlDataAdapter1.Fill(ds, "Customers");
 

Untyped DataSet - FillScheme, Fill (Slowest)

// Fill the typed DataSet's Customer DataTable
DataSet ds = new DataSet();
this.sqlDataAdapter1.FillSchema(ds, SchemaType.Source, "Customers");
ds.Tables["Customers"].BeginLoadData();
this.sqlDataAdapter1.Fill(ds, "Customers");
ds.Tables["Customers"].EndLoadData();
 

Enjoy!    ;-)

2 Comments

Comments have been disabled for this content.