Introducing ASP.NET 2.0 with Visual Studio 2005

This article introduces you to designing and working with an SQL Server 2005 database using the Visual Studio 2005 Integrated Development Environment. You will also learn how to work with the “Grid View” control.

Contributed by
Rating: 4 stars4 stars4 stars4 stars4 stars / 83
January 23, 2006
Rate this Article:
MEH MEH++


SEARCH ASP FREE
TOOLS YOU CAN USE

advertisement

This application is developed with Visual Studio 2005 (Beta Version) on Windows Server 2003 Standard Edition using SQL Server 2005 (Beta Version) as the database.

Something new when creating a new web application

Everyone (mainly .NET developers) anxiously awaited the recent release of the new product Visual Studio.NET 2005 (and of course SQL Server 2005 and BizTalk 2006) from Microsoft, scheduled for November 7, 2005. In this article, we examined what we can do with the new product Visual Studio 2005 together with SQL Server 2005, before it was released (working with betas).

Before proceeding further, just recollect the scenario when Visual Studio.NET (the first version) was released. At that time everyone may have been confused by the large number of features of Visual Studio.NET when compared with Visual Studio 6.0.  Primarily, the biggest change in Visual Studio.NET was a single IDE for all .NET languages. Even though everyone was confused at the beginning, slowly they picked up on it, and now most developers feel very comfortable working with Visual Studio.NET 2003. Now, Microsoft is not making too many changes from Visual Studio.NET 2003 to Visual Studio.NET 2005.  But there are certain features which are worth discussing (apart from Team based editions of Visual Studio.NET 2005).

I shall go through creating a new project in Visual Studio 2005 before focusing on “database design.”  In previous versions, File->New->Project was enough to create either Windows applications or web applications.  Microsoft made slight changes to the means of creating a new project in its Visual Studio 2005 product, compared with previous versions of Visual Studio.NET products.  Now for Visual Studio 2005, File->New Project will create a Windows application (and others), whereas File->New Website will create a web application.

After clicking on File->New Website, we can select “ASP.NET Web Application” (as shown in Figure 1) to create a web application.

If you carefully look at the above figure, there exists a dropdown list at the bottom, labelled “Location.” In previous versions, you created your applications using a virtual directory (something like “wwwroot”), which is generally administered with IIS.  In fact, IIS seems to be compulsory in previous versions of Visual Studio.NET.

But now, to work with Visual Studio 2005 web applications (or ASP.NET applications), IIS is no longer compulsory.  It comes with its own “thin web server” (a scaled down version of IIS) for developing and testing ASP.NET applications.  You can select “File System” within the “location” dropdown list, if you want to use this thin web server.  If you have installed and configured IIS, then you can go with the option “HTTP” (which is quite similar to VS.NET 2003).  If you want to create the application remotely, then you can go for “FTP.”  For this article, we proceed with “File System” (which is the default).

Please note that Visual Studio 2005 never creates any project files or solution files when you select the “File System” option.  You can directly open the folder using “Open Website” available within the “File” menu.

Connecting to the Database using the Visual Studio 2005 “Server Explorer” Window

After creating the web application (as in the previous section), we will now concentrate on database design using Visual Studio 2005 Integrated Development Environment. Microsoft provides a tool window in Visual Studio 2005 IDE called the “Server Explorer” (which is very similar to the tool window available in Visual Studio.NET 2003).  “Server Explorer” is a management console for any server (or system) and is used to open databases, manage and control the data of different databases, manage system services, and so on.

Microsoft provided flexibility to programmers, so that they will use this window to play with the database from within the same IDE and feel comfortable with going through (or managing) all the database objects like tables, procedures, views, and so forth when they are implementing code.

Whenever you start your page, by default you will see Server Explorer on the screen. If you are unable to find the “Server Explorer” Window, just go to View -> Server Explorer.  Once Server Explorer is on the screen, select “Data Connections” and right click on it. You will have two options now:  “Add Connection” and “Create New SQL Server Database.”

Connecting to Existing Databases

Once you click on “Add Connection” (in the right click menu), the Data source window gets displayed (Fig 2).  Go through the following paragraphs to provide the details for the database.

In Figure2 we can go through each and every option in detail as follows:

Server Name: Provide the database Instance name as Server Name with the required path.  If the database resides with in the same system, then we can mention it as “.” (which means “local”). By default, SQL Server 2005 Express edition is automatically installed when the Visual Studio 2005 product is installed. If not, we have to provide the instance name exactly (we can also provide <IP address>\<Instance>).

Log on to the Server: If your SQL installation is based on “Windows Only” authentication, select “Windows Authentication.” If your installation supports “Mixed authentication,” you can provide “username” and “password.”

Select or Enter database name: If the above information is perfect, then you will be able to see all the databases that are available on that particular database instance. Select the required database name from the dropdown list.

Finally, click “ok.”  You can also test the database connection using “Test Connection” button.

Creating New Databases

The second way of connecting databases is by creating a new database itself from Server Explorer. Here it will ask for Server Name, Authentication and Database Name (Fig 3).

Provide values accordingly. It creates a new database, and adds it to the server explorer.

Working with Tables and the New “Grid View” Control

Creating a Table:

  • Open the “Table” group of the same connection in “Server Explorer,” right click on it and click “Add New Table.” The table designer gets opened, allowing us to add the required columns with their respective data types, nulls, relationships, and so on. 
  • Add details as shown in figure 4 and save it with the table name “EmployeeDetails.”


  • Select the “EmployeeDetails” table, right click on it and click “Show Table Data.” Provide data to as shown in figure 5. Every modified cell gets marked with a Red icon (shown in the figure) unless you save it (or move to the next row).

Similarly, create one more table by name “DepartmentDetails” and insert relevant data as shown in the figure below.

Accessing Data: The new control “Grid view” (of ASP.NET), considered to be the most powerful and beautiful control of Visual Studio 2005, has been introduced with much more powerful features than the data grid. It fulfills almost all the requirements of the developer, to simply play with all the properties and tasks such as paging, sorting, editing, deleting, selecting and so on without writing a single line of code!  By directly dragging the database table from the Server Explorer Window onto the design pane, it displays table information in the form of a grid (which is not supported in previous versions of VS.NET).

Now we will go through each and every step, by utilizing this powerful control:

  • Select the “EmployeeDetails” table (in server explorer) and drag it onto the “default.aspx” pane.  Your screen should look something like in Fig 6.


  • On top of the grid view, carefully observe a small arrow button. It gives you plenty of options to play with.  You can even produce perfect sorted, formatted data for the grid right from the same button.  Apart from all of this, you will be able to update data within the grid itself, just by selecting a few options.

Using the above approach, we can create, modify or delete data from within the “grid view” control (which directly affects the database).  Try to experiment with all of those options by executing the solution.

Creating Data Diagrams and Views using the Visual Studio 2005 “Server Explorer” Window

Data Diagram:

  • Select the Data Diagram object, right click on it and click on “Add New Diagram” option
  • Select each and every table, whatever is required and click the “Add” button. Added tables will be displayed on the design pane. From the design pane we can establish relationships by dragging and dropping a child column onto the parent column (between the two tables) very easily. We can even add new tables to the diagram using the “New Table” icon on the toolbar. Try to create a relationship like the one shown in the following Figure 7.

  • After creating a database diagram, save it as Diagram1.

Views:

  • Add a new View similar to the above diagram object. Select required tables, views, functions or synonyms and add to the design pane.
  • You will be able to observe that the window is divided into four panes.
    • Diagram Pane: represents all objects (and their relations) in the form of diagrams.
    • Criteria Pane: can provide conditions within this pane.
    • SQL Pane: can directly specify (or modify) the SELECT statement, which is used to create the view.
    • Result Pane: displays sample output of created view.

In Figure 8, I created a view and executed it to display employee details along with their department names and the location of departments.  Try to design it experimentally.

 

Any comments, suggestions, bugs, errors, feedback etc. are highly appreciated at jag_chat@yahoo.com.

blog comments powered by Disqus
ASP.NET ARTICLES

- Implementing ASP.NET 4.0 Page.MetaDescriptio...
- ASP.Net Development Tips
- Intro to Sessions in ASP.Net
- Google Maps API Introduction in ASP.NET usin...
- Creating an ASP.NET 3.5 Gridview Image Galle...
- Encrypt QueryString in ASP.NET 3.5 using VB....
- ASP.NET 3.5 Drop Down List Controls
- Connect to Access Database with ASP.Net
- Secure Audio Streaming with ASP.Net and Flash
- Dynamic Sitemap and Navigation in ASP.Net
- Implement Gzip and Deflate Compression in AS...
- Run ASP.Net in Ubuntu with Apache
- ASP.Net Mono Website Contact Forms
- ASP.Net URL Rewriting Methods
- Murach`s ASP.NET 4 Web Programming with C# 2...

ASP Web Hosting ASP.Net Web Hosting Windows Web Hosting
 
 
 

ASP Free Forums 
 RSS  Tutorials RSS
 RSS  Forums RSS
 RSS  All Feeds
Site Map 
Request Media Kit
Write For Us Get Paid 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Privacy Policy 
Support 


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 10 - Follow our Sitemap
Most Popular Topics
All ASP.Net Tutorials