What is a Strongly Typed DataSet?

Posted on February 4, 2007. Filed under: classes, introduction |

In my quest to learn ASP.NET I have stumbled across the DataSet object.

A DataSet is an in-memory cache of tables, obtained from a relational database or an XML document.

Unfortunately, IntelliSense does not work well with DataSet objects. You must remember the database table and column names. For example, working with untyped DataSet you would write:

string firstName = dS.Tables["Customers"].Rows[0]["FirstName"].ToString();

As well as remembering column names, you have to use methods such as ToString() to get the correct data type out.

This is where Strongly Typed DataSets come to the rescue. The line of code above can be rewritten when using a Strongly Typed DataSet:

string firstName = dS.Customers[0].FirstName;

Witness, there’s no conversion from one type to another and IntelliSense works. These two benefits alone are worth the trouble of using Strongly Typed DataSets because it will drastically reduce the number of typing errors one makes.

Further Reading

I thoroughly recommend reading Efficient Coding With Strongly Typed DataSets to get to grips with the benefits of using Strongly Typed DataSet objects.

Make a Comment

Make a Comment: ( 1 so far )

blockquote and a tags work here.

One Response to “What is a Strongly Typed DataSet?”

RSS Feed for dotnetting Comments RSS Feed

stay away from datasets, they are evil! stick with creating your own business objects.


Where's The Comment Form?

Liked it here?
Why not try sites on the blogroll...