---
title: "Filling typed datasets using Data Access Application Block v.2.0"
url: "https://osherove.com/blog/2003/7/28/filling-typed-datasets-using-data-access-application-block-v.md"
canonical: "https://osherove.com/blog/2003/7/28/filling-typed-datasets-using-data-access-application-block-v.html"
published: "2003-07-28T11:40:00"
updated: "2003-07-28T11:40:00"
tags: [".Net Original"]
author: "Roy Osherove"
description: "The new Microsoft Data Access Application Block is out, and it contains some nice changes. One of the nicest (and simplest) is the ability to fill a dataset (that may or may not be strongly typed) using the SQLHelper…"
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/"
---

# Filling typed datasets using Data Access Application Block v.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.

The new _Microsoft Data Access Application Block_ is out, and it contains some nice changes.

One of the nicest (and simplest) is the ability to fill a _dataset_(that may or may not be strongly typed) using the _SQLHelper_ class.

Let’s say that I have created a strongly typed DataSet named ds.

Also, let’s say I have 3 tables in the DB that I’d like to fill my dataset from.

It’s pretty simple, actually.

SqlHelper.FillDataset(Connection String ,Command Type,SELECT statement , Dataset variable ,Table mapping array)

**Connection string**:      You guessed it.

**Command Type**:         Can be either Text(Select statement) or StoredProcedure(name of an SP in the database).

                                    CommandType.TableDirect  will not work with the .Net Sql client data provider.

**Select Statement**:       You guessed it again

**Dataset variable**:        the dataset to fill

**Table mapping array**: this is pretty important. You need to pass in an array containing the name of the actual table you are going to fill in your dataset, otherwise the sql helper will create a new table in your dataset named “table”, “table1”.. and so on.

So this is the code I wrote to fill my dataset:

public ApartmentDataset GetDataset()

{

ApartmentDataset ds = new ApartmentDataset();

SqlHelper.FillDataset(CON\_STRING,CommandType.Text,

"select \* from Apartments",ds,new string\[\]{"Apartments"});

SqlHelper.FillDataset(CON\_STRING,CommandType.Text,

"select \* from Cities",ds, new string\[\]{"Cities"});

SqlHelper.FillDataset(CON\_STRING,CommandType.Text,

"select \* from Statuses",ds, new string\[\]{"Statuses"});

return ds;

}

Kinda wordy, ain’t it? Can you see the pattern here?

So I created this small helper function :

private void FillDatasetTable(string tableName,DataSet ds)

{

SqlHelper.FillDataset(

CON\_STRING,

CommandType.Text,

"select \* from " + tableName,

ds,

new string\[\]{tableName});

}

So now my code for filling and returning the dataset looks and reads much better:

public ApartmentDataset GetDataset()

{

      ApartmentDataset ds = new ApartmentDataset();

      FillDatasetTable("Apartments",ds);

      FillDatasetTable("Cities",ds);

      FillDatasetTable("Statuses",ds);

      return ds;

}

**Update:**

This just goes to show how an outside perspective can help out. [Lior Rozner](http://weblogs.asp.net/lrozner/) just sent over a much cleaner way of filling your Dataset object, filling multiple tables in one go:

 public ApartmentDataset GetDataset()

{

ApartmentDataset ds = new ApartmentDataset();

SqlHelper.FillDataset(CON\_STRING,CommandType.Text,

"select \* from Apartments " +

"select \* from Cities " +

"select \* from Statuses ",

ds,

new string\[\]{"Apartments",

"Cities",

"Statuses"}); 

return ds;

}

Thanks, Lior!

**Another Update:**

There's a bug in the Data Access Blocks. [Here's the fix!](http://weblogs.asp.net/rosherove/posts/10614.aspx)

## More in .Net Original

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

- Jul 28, 2003

    ### [Nasty bug in Data Access Block Ver. 2.0](https://osherove.com/blog/2003/7/28/nasty-bug-in-data-access-block-ver-20.html)

- Jul 28, 2003

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

- Jul 28, 2003

    ### [Checking for NULL values](https://osherove.com/blog/2003/7/28/checking-for-null-values.html)

- Jul 27, 2003

    ### [C++ for programmers](https://osherove.com/blog/2003/7/27/c-for-programmers.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/
