Questions That Should Be Asked More Frequently

Q

Of my three options for creating DataTable objects, which should I use?

  • Creating them using code before populating them using a SqlDataAdapter

  • Creating them implicitly by calling SqlDataAdapter.Fill

  • Creating them by calling SqlDataAdapter.FillSchema

A

I strongly recommend the first option. As of this writing, creating tables using code is about 20 times faster than calling the FillSchema method of the SqlDataAdapter.

Q

I created my DataTable objects in code, as you recommended, but now the code that fills my DataTable objects runs much more slowly. Why is that?

A

I’m so glad you asked. You’ll see this slowdown if your DataTable objects have constraints. As you retrieve data from your data store and add rows ...

Get Programming Microsoft® ADO.NET 2.0 Core Reference, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.