You will have to set up a database connection using Server
Explorer; it is located at the left side of the IDE above the ToolBox panel, or
it can be accessed using the View | Server Explorer menu.
1) Click on the Server Explorer panel, right-click on Data
Connections, and select the Add Connection option.
2) In the window that pops up, select the Microsoft SQL
Server Database file option and create a new database file called FormWizard_db.mdf.
Set your login credentials as appropriate for your server; the default is
Windows Authentication.
3) At this stage you can select the default settings, and the
database will be created for you by Visual Studio.
4) You will notice the database in the Server Explorer once
it is created.
5) Click on the database name to expose the nodes
underneath. Right-click on the Tables node and add a new table with these columns:
id - varchar(10)
Fname - varchar(10)
Lname - varchar(10)
Email - varchar(50)
Tel - varchar(20)
Choose to Save Table and name this new table Table1.
6) Add a stored procedure called dbo.StoredProcedure1 by
right-clicking on the Stored Procedures node on the Server Explorer. The code
for this stored procedure can be found in Listing 1.
Listing 1 - Stored Procedure dbo.StoredProcedure1
CREATE PROCEDURE dbo.StoredProcedure1
@Fname varchar(10),
@Lname varchar(10),
@Email varchar(50),
@Tel varchar(20)
AS
INSERT INTO table1 (Fname, Lname, Email, Tel)
VALUES (@Fname, @Lname, @Email, @Tel)
RETURN
7) Create the connection string in the web.config file as
shown in Listing 2.
Listing 2 - connectionStrings section of web.config
<connectionStrings>
<add name="dbConnectionString"
connectionString="Data
Source=.\SQLEXPRESS;AttachDbFilename=C:\Inetpub\wwwroot\FormWizard\App_Data\FormWizard_db.mdf;Integrated
Security=True;Connect Timeout=30;User Instance=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
Note: You should modify the path of the database file
accordingly.