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 <strong>screenshot</strong> ) with only one page ( <strong>default.aspx</strong> ) that has a GridView control. More on this control in a few steps.
Step 2 - Adding a database connection. For this exercise I have <strong>SQL Server Express 2005</strong> 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 <strong>shown</strong> ).
- Select SQL Server as the <strong>data provider</strong> .
- Select the Server and the database you want to connect to. e.g. <strong>here</strong> 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 <strong>shown</strong> .
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 <strong>see</strong> , 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 <strong>autoformats</strong> 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 <strong>shown</strong> the data is automatically selected and shown in the selected format. You can also <strong>update the records</strong> if authorised to do so and also <strong>sort and paginate</strong> 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 <strong>code-beside</strong> 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 <strong>built-in web server</strong> , 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 <strong>references</strong> , set <strong>build options</strong> and set <strong>accessibility options</strong> 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 <strong>see</strong> , it failed and that too miserably. You can also of course set both the <strong>Startup</strong> and <strong>MSBuild</strong> 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 <strong>tool</strong> that makes their job easier. You can setup the <strong>security</strong> , <strong>manage profiles</strong> , <strong>manage applications</strong> and the <strong>data provider</strong> .
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!