Data Access overview (with Screenshots) in ASP.NET 2.0 using Visual Studio 2005

I wanted to walk you through a quick demo on some of the enhancements for data access in Visual Studio 2005. Please note that though I have a bunch of screen shots, the application here is pretty simple. My goal is not to show you the power of the new stuff that makes the developer more productive and a lot of it is the small stuff – which all adds up to a fair amount of FTE’s. So, lets start.

Step 1 – I am going to create a new web site project (as shown in the screenshot) with only one page (default.aspx) that has a GridView control. More on this control in a few steps.

Step 2 – Adding a database connection. For this exercise I have SQL Server Express 2005 installed, but there is no reason why you cannot do this with SQL Server 2000 or MSDE. I am going to use the sample pubs db for this. Here are the steps:

  • Add a new connection (as shown).
  • Select SQL Server as the data provider.
  • Select the Server and the database you want to connect to. e.g. here I connect to the pubs db.

Step 3 – Now that you are connected to a database we would want to add a table. I select the author table and drag and drop it to the default page as shown.

Step 4 – When you drag and drop the table, Visual Studio automatically created a GridView control. This control automatically picks up the various columns from the table by default. You can configure the data source to your needs, configuring all the selects, updates and deletes. As you can see, the control also has built in paging, sorting, updating (if there is such a word), etc. You can also select one of the many built-in autoformats to give the control a cool and consistent look and feel.

What is a GridView control? A GridView control, allows you can display, edit, and delete tabular data from many different kinds of data sources, including databases, XML files, and the data exposed by a business object. is the successor to the DataGrid control. This controls displays the values of a data source in a table where each column represents a field and each row represents a record. The GridView control allows you to select, sort, and edit these items. I will detail out the differences between the two in another post.

Step 5 – Lets give it a spin. Press Ctrl+F5, to compile and run the app. As shown the data is automatically selected and shown in the selected format. You can also update the records if authorised to do so and also sort and paginate the rows returned automatically.

Step 6 – Well we don’t really have any more steps, but I want to show you what the project and the code looks like. You can see the default.aspx in design mode and the source mode. Now onto the more interesting stuff, lets see what the code-beside looks like. Interesting right, there is not a single line of code!

Here are some more screen shots showing the configuration of Visual Studio 2005.

  • In Built Web Server – There is built-in web server, so one does not need IIS installed. This will help answer a lot of companies (especially in the Enterprise environment) security issue of having IIS run on every developer’s machine and not tightened down. This server can be accessed only locally and not via a remote machine. Also, this starts only when you run an application (either in Debug or Release mode) and is shutdown when you stop the application.
  • Web Site Properties – There are a bunch of new properties of a web applications. You can add references, set build options and set accessibility options which are cool. They allow to ensure your application meets the required standards. e.g. most companies that do business with the federal government need to adhere their web sites to Section 508. When I checked the default.aspx for all the accessibility options, unfortunately as you can see, it failed and that too miserably. You can also of course set both the Startup and MSBuild options.
  • Web Site Admin Tool – The admins in your organisation will love this. Till now the only way to modify this was manually updating the .config file, which means either the admins need to understand the various sections in the .config files or the developers need to provide extremely good documentation (now there is an oxymoron), that would help the admins. But in ASP.NET 2.0 there is a tool that makes their job easier. You can setup the security, manage profiles, manage applications and the data provider.

Summary – To summarise, the demo in itself is nothing great from a technical perspective, but what is interesting is that a developer did not have to write one single line of code. To achieve the same today (in ASP.NET), is not difficult, but does take considerable effort to write, unit-test and debug, especially when you account for the updates of rows, pagination, sorting, etc. Just a small sampling of the new power of ASP.NET 2.0 in Whidbey and all the host of new features that promise to make the live of a developer much better!

Published by

Amit Bahree

This blog is my personal blog and while it does reflect my experiences in my professional life, this is just my thoughts. Most of the entries are technical though sometimes they can vary from the wacky to even political – however that is quite rare. Quite often, I have been asked what’s up with the “gibberish” and the funny title of the blog? Some people even going the extra step to say that, this is a virus that infected their system (ahem) well. [:D] It actually is quite simple, and if you have still not figured out then check out this link – whats in a name?

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.