Replicating GetRows in .NET

Let's Explain

Let's Explain

The first thing in our .NET code above is importing our Data namespaces to allow us to call our objects so we can connect to the data. Next we declare all our variables. We then set-up our database connection and call the DataAdapter to open and query our data source. Now within our called DatAdapter we expose our DataSet which is a disconnected storage container of the tables holding our data, and this can hold a lot of tables.

By means of our DataSet we are offered much control over our data presentation. The DataSet upon creation stores and exposes a collection of rows and columns or a DataTable object (which stores one in-memory table), with which we can manipulate and view our results, even updating, deleting, and inserting.

Now after I queried the database and filled the DataSet with the help of the DataAdapter, I exposed our DataTable object with GetRows - a DataTable declared variable object, and got some precise information on what it contains.

I wanted to know how many columns and rows there are and with the DataTable.Rows.Count and DataTable.Columns.Count I get that. Next, I use .NET's cool new string building method - the StringBuilder to build my table. It was filled with two loops - one loop for telling us the columns name by GetRows.Columns(c).ToString() method and another loop for our row information like so GetRows.Rows(x)(y).ToString() , whereby x indicates row number and y is column number.

Then I send out my results as a string to the tag below and that's it.


Here I have demonstrated a very simple and easy way of migrating your old GetRows code exactly over to .NET. You may at times simply employ many of the native .NET controls to display your data if you feel that'll be enough, but you may at times run into snags like I have and this was the only satisfactory way of displaying my data in the way I needed to.

So when it comes to migrating legacy code, .NET does it and more, and with so much more power, performance and class, and without compromising any flexibility whatsoever.

You might also like...


About the author

Dimitrios Markatos

Dimitrios Markatos United States

Dimitrios, or Jimmy as his friends call him, is a .NET developer/architect who specializes in Microsoft Technologies for creating high-performance and scalable data-driven enterprise Web and des...

Interested in writing for us? Find out more.


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Before software should be reusable, it should be usable.” - Ralph Johnson