---
title: "Quick & Easy ADO.NET Speed Improvements"
url: "https://osherove.com/blog/2003/6/27/quick-amp-easy-adonet-speed-improvements.md"
canonical: "https://osherove.com/blog/2003/6/27/quick-amp-easy-adonet-speed-improvements.html"
published: "2003-06-27T20:04:00"
updated: "2003-06-27T20:04:00"
tags: [".Net Original"]
author: "Roy Osherove"
description: "OK, I coudn't resist... 1) It’s about 20 times faster to create DataTables in your dataset using code, than letting your DataAdapter create them. 2) A very good potential for speed improvement lies when filling a…"
usage: "Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page)."
license: "https://creativecommons.org/licenses/by/4.0/"
---

# Quick & Easy ADO.NET Speed Improvements

By Roy Osherove June 27, 2003 In [.Net Original](https://osherove.com/blog/category/net-original)

**Historical article** · Originally published June 27, 2003; technical details may be outdated.

OK, I coudn't resist...

1) It’s about 20 times faster to create DataTables in your dataset using code, than letting your DataAdapter create them.

2)  A very good potential for speed improvement lies when filling a DataSet with DataTables that have constraints such as PrimaryKeys.
As the DataAdapter adds each row to the DataTable, it has to check that the new row meets the constraints of the table. This means significant slowdown when loading a dataset. Usually, your dataset will have the same constraints as the database you pulled the data from, meaning there’s no reason to check validity of data again.
**Easy solution** -  the DataSet contains a property called ‘_EnforceConstraints’_ which is by default set to _True_. Just set this property to _False_ before filling up the Dataset and you’ll save all that precious validation time.

If you're working with just a single DataTable object, you can use the _BeginLoadData_ and _EndLoadData_ methods of the DataTable to achieve the same goal.

## More in .Net Original

[All posts in .Net Original](https://osherove.com/blog/category/net-original)

- Jun 30, 2003

    ### [.Net Deep Dive Recap](https://osherove.com/blog/2003/6/30/net-deep-dive-recap.html)

- Jun 29, 2003

    ### [FillSchema and AddWithKey Don't Operate As Promised?](https://osherove.com/blog/2003/6/29/fillschema-and-addwithkey-dont-operate-as-promised.html)

- Jun 22, 2003

    ### [Disabling Connection Pooling](https://osherove.com/blog/2003/6/22/disabling-connection-pooling.html)

- Jun 22, 2003

    ### [A Little Macro To Automate Creating Connection Strings](https://osherove.com/blog/2003/6/22/a-little-macro-to-automate-creating-connection-strings.html)


---

## About the author

**Roy Osherove**: Senior Solutions Architect at AWS working on AI for production and AI-driven development; author of The Art of Unit Testing and Elastic Leadership, with about 20 years of consulting and training on unit testing, TDD, team leadership and continuous delivery.

### Sites

- [RobotPaper](https://robotpaper.ai/): This blog: AI patterns and anti-patterns, AI and coding agents, and engineering leadership.
- [osherove.com](https://osherove.com): Roy's personal site. Author of The Art of Unit Testing and Elastic Leadership; consulting and training on unit testing, TDD, team leadership and continuous delivery, plus about 20 years of blog posts.
- [The Art of Unit Testing](https://www.artofunittesting.com): The Art of Unit Testing, 3rd Edition (Manning): readable, maintainable, trustworthy unit tests, plus TDD workshops in C#, JavaScript, Java and Kotlin.
- [5whys.com](https://www.5whys.com): Roy's writing on software team leadership: self-organizing teams, surviving chaos, learning mode and the Elastic Leadership model.
- [Pipeline Driven](https://pipelinedriven.org): Continuous delivery and DevOps practices: build patterns, pipeline-friendly testing, DevOps metrics and enterprise DevOps.
- [Elastic Leadership](https://www.elasticleadership.com): Elastic Leadership, Roy's framework for software team leaders (survival, learning and self-organizing modes).

### Social

- X: https://x.com/royosherove
- LinkedIn: https://www.linkedin.com/in/osherove/

### Contact

- Contact form: https://forms.gle/jQSx5KoXvrVA1JCK7

### License

Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page). License: https://creativecommons.org/licenses/by/4.0/
