---
title: "Nasty bug in Data Access Block Ver. 2.0"
url: "https://osherove.com/blog/2003/7/28/nasty-bug-in-data-access-block-ver-20.md"
canonical: "https://osherove.com/blog/2003/7/28/nasty-bug-in-data-access-block-ver-20.html"
published: "2003-07-28T18:10:00"
updated: "2003-07-28T18:10:00"
tags: [".Net Original"]
author: "Roy Osherove"
description: "Thanks to Mark Brown for discovering this bug in the Data Access Block Ver. 2.0. Short answer: Here's how to fix the data access bug: Open the SQLHelper.cs file look for the line that contains this line of code: C#:…"
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/"
---

# Nasty bug in Data Access Block Ver. 2.0

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

**Historical article** · Originally published July 28, 2003; technical details may be outdated.

Thanks to [Mark Brown](http://www.dotnetjunkies.com/weblog/markbrown/) for [discovering this bug](http://www.dotnetjunkies.com/weblog/markbrown/posts/454.aspx) in the Data Access Block Ver. 2.0.

**Short answer:**

Here's how to fix the data access bug:

- Open the _SQLHelper.cs_ file
- look for the line that contains this line of code:

**C#:**  tableName += (index + 1).ToString();

**VB:**  tableName = tableName & (index + 1).ToString()

- Replace it with this line of code:

**C#:**  tableName= "Table" + (index + 1).ToString();

**VB:** :  tableName = "Table"  & (index + 1).ToString()

- That's it.

**Long answer**

The bug is introduced when you try to use the _SQLHelper.FillDataSet_() method. basically the helper allows you to send in many SELECT statements, and pass in the names of the tables that the SELECTs will fill.

The table names are used to create TableMappings between the table names you provide and the tables that the SELECT statements will create in the dataset. A very nifty idea, only the idea is killed right at the third table because down under, the helper loops through the table names and maps each table to a corresponding default table name with a sequential number, so if I send _"MyFirstTable","MYSecondTable","MyThirdTable"_ in the table names string array, they should be mapped to _"Table","Table1","Table2"_ respectively.

sadly, what really happens is that the third table will be mapped to a table named "Table12" instead of "Table3". And it's all because of this line:

**C#:**  tableName += (index + 1).ToString();

**VB:**  tableName = tableName & (index + 1).ToString()

After two loops, tablename will already be "Table1", so anything you concatenate to it will just mess everything up. that's why changing it to this line will work every time:

**C#:**  tableName= "Table" + (index + 1).ToString();

**VB:** :  tableName = "Table"  & (index + 1).ToString()

## More in .Net Original

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

- Aug 11, 2003

    ### [Server.Transfer vs. Response.Redirect](https://osherove.com/blog/2003/8/11/servertransfer-vs-responseredirect.html)

- Jul 28, 2003

    ### [About coding standards](https://osherove.com/blog/2003/7/28/about-coding-standards.html)

- Jul 28, 2003

    ### [DataReader.HasRows](https://osherove.com/blog/2003/7/28/datareaderhasrows.html)

- Jul 28, 2003

    ### [Filling typed datasets using Data Access Application Block v.2.0](https://osherove.com/blog/2003/7/28/filling-typed-datasets-using-data-access-application-block-v.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/
