Building Data Aware Web Applications with ASP.NET - Part 1
Nowadays, nearly every web site provides a facility for its users to register on the site. Sometimes, it may be compulsory to register on a site to avail certain services. For instance, imagine you are developing an e-commerce shopping store where your users should create a user id and password to login and begin shopping on that site. Not only registration but also an effective authentication system should have to be developed so that users are properly and securely verified before doing any business with your site. Apart from the above features you should also provide updating, searching and deleting capabilities for your users. In a series of articles, you will learn how to perform these tasks using ASP.NET with Visual Basic .NET as the programming language and SQL Server as backend database.
If you have experience with classic ASP then you are right at home. However, there are some unique features in ASP.NET as compared to Classic ASP. Firstly, the .NET Framework provides a namespace exclusively devoted to SQL Server (System.Data.SQLClient) and functionalities like DataGrid, Templates etc. You can easily populate the relevant data in a DataGrid, which will show the information in a table like fashion. You can also modify it according to your specific needs.
In this article, you will learn how to add records to a database. I assume that you have installed the .NET Framework SDK Final Release under Windows 2000 Professional / Windows XP Professional environment. I recommend Visual Studio .NET or ASP.NET WebMatrix for coding purposes. The WebMatrix is easy to download and install and is suitable for learning purposes; however, it doesn't supports intellisense. Visual Studio .NET does provide intellisense, which provides advanced sensing capabilities by detecting each and every variable, methods etc. Intellisense automatically shows the syntaxes of the methods in various versions. You can also use plain Notepad, if you are prepared to enter all code from scratch.
Wintergreen is a consulting firm providing custom web development solutions. The management decides to develop a web-based application for adding employee's information to its database. For this purpose, they have decided to create a simple user-interface as shown in Figure 1.1. As part of this project, they also require creation of a database, table and a stored procedure.
Creation of a database
create database Wintergreen
Creation of table
create table Employees(id int not null identity, name varchar(50), age int, email varchar(50), address varchar(100), username varchar(50), password varchar(50))
Creation of Stored Procedure
create procedure Toregister ( @name varchar(50), @age int, @email varchar(50), @address varchar(100), @username varchar(50), @password varchar(50) ) as if exists -- You cannot register usernames already registered on the database twice. ( select username from Employees where username = @username ) return 1 else insert Employees(name,age,email,address,username,password) values(@name,@age,@email,@address,@username,@password)
Page 1 of 2