Data Access and Data Binding Sample Application Setup

Ok so you have Visual Studio or Web Developer Express installed, have installed SQL Server Express, and have downloaded and run the SQL Samples from the previous post.

Lets create our Web Project, select Create Project and select either a C# or a VB.Net ASP.NET Web Application, you can create this project anywhere you want, for reference I'm just putting mine locally and using the built in web server.

Now we'll add the Northwinds Database to our project.  Right click on the App_Data and select Add->Existing Item and navigate to the C:\SQL Server 2000 Sample Databases folder or wherever you installed them and selecting Northwnd.mdf and select 'Add'.  It should now appear under your App_Data directory.

Now let's test out connection by doing one of the traditional 'Whizz Bang' marketing demos, where we'll drop a table from Northwinds right on to the page and kapow data displayed without writing a single line of code.

First, open up your default.aspx page and switch to design view.

Next make sure you have the Server Explorer window open, if it's not open you can open it by selecting View->Server Explorer.

Next in the Server Explorer window, expand the Northwind Data Connection, then expand the the Tables folder. 

Now for the fun part select the Customer table and drag and drop it on to the blank design surface.  Kapow!  Now let's view it in the browser by right clicking on the design surface and selecting View In Browser.  There you have it a bound data control with zero lines of code. Please see my note below for a little trouble I had with VS2008 and Vista.

So let's see what happened, first a SqlDataSource (In the next post I'll describe the SqlDataSource and some of it's features) was created with parameters that selected all the rows from the Customer table.  Then a GridView was placed on the page and bound to the SqlDataSource.  All this was done automagically for you.

Ok so now our environment is all set.  Feel free to play around with the GridView, try using the themes and fiddle with the properties.

In the next post I'll discuss the SqlDataSource in more detail and discuss the pros and cons of the control.  In some later posts I'll go into detail in how you can take control of the GridView and override some of it's default behaviors including nested data sources and additional GridViews.

Note: I'm running Vista Ultimate 32bit, and when I first tried to view the web page I got an error page.  This happened to any page I created even if it just had text.  Turns out it has something to do with IPv6 on Vista...after looking around I found Rob Bazinet's blog The Accidental Technologist in which he encountered the same problem.  Through discussions on the blog a work around was presented to edit the hosts file and comment out the line that contains ::1 Check the link to the post for details.  What was really weird is that I know I've created sites just fine before...so I don't know if it was a recent update that did it...but it works now...weird.

Published Friday, April 11, 2008 5:41 PM by ryansjedi
Filed under: ,

Comments

# Web Design » Data Access and Data Binding Sample Application Setup@ Saturday, April 12, 2008 12:05 AM

Pingback from  Web Design » Data Access and Data Binding Sample Application Setup

# Data Access - The SqlDataSource Part 1@ Saturday, April 12, 2008 11:45 PM

Welcome back! If you are following along from the last post , you'll notice that two controls were automatically

Leave a Comment

(required) 
(required) 
(optional)
(required)