How to create a very simple registration form in ASP.NET Web forms.
Step 1.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace Registration2
{
public partial class Registration : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnsave_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("usp_employee_insert", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Name", TextName.Text);
cmd.Parameters.AddWithValue("@Age", TextAge.Text);
cmd.Parameters.AddWithValue("@Address", TextAddress.Text);
cmd.Parameters.AddWithValue("@Password", TextPassword.Text);
cmd.Parameters.AddWithValue("@CPassword", TextCPassword.Text);
cmd.Parameters.AddWithValue("@Phone", TextPhone.Text);
cmd.Parameters.AddWithValue("@Salary", TextSalary.Text);
cmd.ExecuteNonQuery();
con.Close();
}
}
}
step 9. Web.config file Connection string add to database
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<connectionStrings>
<add name="DBCS" connectionString="data source=Shiva;integrated security=true;initial catalog=databasename"/>
</connectionStrings>
</configuration>
Step 10. Data base code.
create database databasename
use databasename
create table Employee
(
Empid int primary key identity(1,1),
Name varchar(50),
Age int,
Address varchar(50),
Password varchar(50),
CPassword varchar(50),
Phone varchar(11),
Salary int
)
select * from Employee
how to create insert procedure in sql-
create proc usp_employee_insert
@Name varchar(50),
@Age int,
@Address varchar(50),
@Password varchar(50),
@CPassword varchar(50),
@Phone varchar(11),
@Salary int
as
begin
insert into Employee(Name,Age,Address,Password,CPassword,Phone,Salary) values(@Name,@Age,@Address,@Password,@CPassword,@Phone,@Salary)
end
Step 1.
Step.2 Create new project in Visual Studio 2012
Go to File-> New-> Project-> Visual C#-> Web ->ASP.NET Empty Web Application->
Entry Project Name-> OK.
Step 3. Create new web form in web project.
Right click on Project Name->> Add
Step 4. How to create Web Form
Add New Item->>Visual C#->> Web ->>Web Form- >>write the
Web form name with .aspx extension->>Add
Step 5. HTML Source code of registration form.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Registration.aspx.cs" Inherits="Registration2.Registration" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>Name:</td>
<td><asp:TextBox ID="TextName" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>Age:</td>
<td><asp:TextBox ID="TextAge" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>Address:</td>
<td><asp:TextBox ID="TextAddress" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>Password:</td>
<td><asp:TextBox ID="TextPassword" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>CPassword:</td>
<td><asp:TextBox ID="TextCPassword" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>Phone:</td>
<td><asp:TextBox ID="TextPhone" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>Salary:</td>
<td><asp:TextBox ID="TextSalary" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td></td>
<td><asp:Button ID="btnsave" runat="server" Text="Save" OnClick="btnsave_Click" /></td>
</tr>
</table>
</div>
</form>
</body>
</html>
Step 6. Back end code .cs page c# code.
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Registration2
{
public partial class Registration : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnsave_Click(object sender, EventArgs e)
{
}
}
}
Step.7 Add the three Namespace 2012.
1.using System.Data;Step 8.
2.using System.Data.SqlClient;
3.using System.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace Registration2
{
public partial class Registration : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnsave_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("usp_employee_insert", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Name", TextName.Text);
cmd.Parameters.AddWithValue("@Age", TextAge.Text);
cmd.Parameters.AddWithValue("@Address", TextAddress.Text);
cmd.Parameters.AddWithValue("@Password", TextPassword.Text);
cmd.Parameters.AddWithValue("@CPassword", TextCPassword.Text);
cmd.Parameters.AddWithValue("@Phone", TextPhone.Text);
cmd.Parameters.AddWithValue("@Salary", TextSalary.Text);
cmd.ExecuteNonQuery();
con.Close();
}
}
}
step 9. Web.config file Connection string add to database
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<connectionStrings>
<add name="DBCS" connectionString="data source=Shiva;integrated security=true;initial catalog=databasename"/>
</connectionStrings>
</configuration>
Step 10. Data base code.
create database databasename
use databasename
create table Employee
(
Empid int primary key identity(1,1),
Name varchar(50),
Age int,
Address varchar(50),
Password varchar(50),
CPassword varchar(50),
Phone varchar(11),
Salary int
)
select * from Employee
how to create insert procedure in sql-
create proc usp_employee_insert
@Name varchar(50),
@Age int,
@Address varchar(50),
@Password varchar(50),
@CPassword varchar(50),
@Phone varchar(11),
@Salary int
as
begin
insert into Employee(Name,Age,Address,Password,CPassword,Phone,Salary) values(@Name,@Age,@Address,@Password,@CPassword,@Phone,@Salary)
end
No comments:
Post a Comment