Asp.Net Projects with Source Code



Login code

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Net;
//using System.Web.HttpCookie;

namespace WebApp
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btn_login_submit_Click(object sender, EventArgs e)
        {
            //SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-BM4R8M0;Initial Catalog=WinApp;Integrated Security=True");
            string projectConnection = ConfigurationManager.ConnectionStrings["kitConnection"].ConnectionString;
            SqlConnection con = new SqlConnection(projectConnection);
            con.Open();
            SqlCommand cmd = new SqlCommand("sp_login", con);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlParameter param1 = new SqlParameter("@uname", SqlDbType.VarChar);
            cmd.Parameters.Add(param1).Value = txtbox_login_uname.Text;
            SqlParameter param2 = new SqlParameter("@pwd", SqlDbType.VarChar);
            cmd.Parameters.Add(param2).Value = txtbox_login_pwd.Text;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            int a = Convert.ToInt32(ds.Tables[0].Rows[0][0].ToString());
            
            if (a > 0)
            {
                Response.Redirect("CRUD.aspx" );
            }
            else
            {
                Response.Write("InValid User");
            }
            con.Close();

        }

        protected void btn_NewUser_Redirect_Click(object sender, EventArgs e)
        {
            Response.Redirect("NewUserPage.aspx");
        }
    }
}

New User Registration Page

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;

namespace WebApp
{
    public partial class NewUserPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           
        }

        protected void btn_newusrpg_submit_Click(object sender, EventArgs e)
        {

            try 
            { 
            //SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-BM4R8M0;Initial Catalog=WinApp;Integrated Security=True");
            string projectConnection = ConfigurationManager.ConnectionStrings["kitConnection"].ConnectionString;
            SqlConnection con = new SqlConnection(projectConnection);
            con.Open();
            SqlCommand cmd = new SqlCommand("sp_newuser", con);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlParameter param1 = new SqlParameter("@user_id", SqlDbType.VarChar);
            cmd.Parameters.Add(param1).Value = txtbox_newusrpg_userid.Text;
            SqlParameter param2 = new SqlParameter("@name", SqlDbType.VarChar);
            cmd.Parameters.Add(param2).Value = txtbox_newusrpg_name.Text;
            SqlParameter param3 = new SqlParameter("@uname", SqlDbType.VarChar);
            cmd.Parameters.Add(param3).Value = txtbox_newusrpg_uname.Text;
            SqlParameter param4 = new SqlParameter("@pwd", SqlDbType.VarChar);
            cmd.Parameters.Add(param4).Value = txtbox_newusrpg_pwd.Text;
            int i = cmd.ExecuteNonQuery();

            if (i > 0)
            {
                Response.Write("Registered Sucessfully");
            }
            else
            {
                Response.Write("Registration Failed");
            }
            con.Close();

        }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }

        protected void btn_Login_Redirect_Click(object sender, EventArgs e)
        {
            Response.Redirect("Login.aspx");
        }
    }
}

CRUD Page

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;

namespace WebApp
{
    public partial class CRUD : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btn_Logout_Redirect_Click(object sender, EventArgs e)
        {
            Response.Redirect("Login.aspx");
        }

        protected void btn_crud_insert_Click(object sender, EventArgs e)
        {
            //SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-BM4R8M0;Initial Catalog=WinApp;Integrated Security=True");
            try
            {
                string projectConnection = ConfigurationManager.ConnectionStrings["kitConnection"].ConnectionString;
                SqlConnection con = new SqlConnection(projectConnection);
                con.Open();
                SqlCommand cmd = new SqlCommand("sp_insert", con);
                cmd.CommandType = CommandType.StoredProcedure;
                SqlParameter param1 = new SqlParameter("@crud_id", SqlDbType.VarChar);
                cmd.Parameters.Add(param1).Value = txtbox_crud_userid.Text;
                SqlParameter param2 = new SqlParameter("@name", SqlDbType.VarChar);
                cmd.Parameters.Add(param2).Value = txtbox_crud_name.Text;
                SqlParameter param3 = new SqlParameter("@degree", SqlDbType.VarChar);
                cmd.Parameters.Add(param3).Value = txtbox_crud_degree.Text;
                SqlParameter param4 = new SqlParameter("@place", SqlDbType.VarChar);
                cmd.Parameters.Add(param4).Value = txtbox_crud_place.Text;
                int i = cmd.ExecuteNonQuery();

                if (i > 0)
                {
                    Response.Write("Data Inserted Sucessfully");
                }
                else
                {
                    Response.Write("Data Insertion Failed");
                }
                con.Close(); ;
            }

            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }

        }

        protected void btn_crud_update_Click(object sender, EventArgs e)
        {
            //SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-BM4R8M0;Initial Catalog=WinApp;Integrated Security=True");
            string projectConnection = ConfigurationManager.ConnectionStrings["kitConnection"].ConnectionString;
            SqlConnection con = new SqlConnection(projectConnection);
            con.Open();
            SqlCommand cmd = new SqlCommand("sp_update", con);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlParameter param1 = new SqlParameter("@crud_id", SqlDbType.VarChar);
            cmd.Parameters.Add(param1).Value = txtbox_crud_userid.Text;
            SqlParameter param2 = new SqlParameter("@name", SqlDbType.VarChar);
            cmd.Parameters.Add(param2).Value = txtbox_crud_name.Text;
            SqlParameter param3 = new SqlParameter("@degree", SqlDbType.VarChar);
            cmd.Parameters.Add(param3).Value = txtbox_crud_degree.Text;
            SqlParameter param4 = new SqlParameter("@place", SqlDbType.VarChar);
            cmd.Parameters.Add(param4).Value = txtbox_crud_place.Text;
            int i = cmd.ExecuteNonQuery();

            if (i > 0)
            {
                Response.Write("Data Updated Sucessfully");
            }
            else
            {
                Response.Write("Data Updation Failed");
            }
            con.Close();
        }

        protected void btn_crud_delete_Click(object sender, EventArgs e)
        {
            //SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-BM4R8M0;Initial Catalog=WinApp;Integrated Security=True");
            string projectConnection = ConfigurationManager.ConnectionStrings["kitConnection"].ConnectionString;
            SqlConnection con = new SqlConnection(projectConnection);
            con.Open();
            SqlCommand cmd = new SqlCommand("sp_delete", con);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlParameter param1 = new SqlParameter("@crud_id", SqlDbType.VarChar);
            cmd.Parameters.Add(param1).Value = txtbox_crud_userid.Text;
            
            int i = cmd.ExecuteNonQuery();

            if (i > 0)
            {
                Response.Write("Data Deleted Sucessfully");
            }
            else
            {
                Response.Write("Data Deletion Failed");
            }
            con.Close();
        }

        protected void btn_crud_fetch_Click(object sender, EventArgs e)
        {

            //SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-BM4R8M0;Initial Catalog=WinApp;Integrated Security=True");
            string projectConnection = ConfigurationManager.ConnectionStrings["kitConnection"].ConnectionString;
            SqlConnection con = new SqlConnection(projectConnection);
            con.Open();
            SqlCommand cmd = new SqlCommand("sp_fetch", con);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            GridView.DataSource = ds.Tables[0];
            GridView.DataBind();
            con.Close();
        }

        protected void btn_crud_search_Click(object sender, EventArgs e)
        {
            //SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-BM4R8M0;Initial Catalog=WinApp;Integrated Security=True");
            string projectConnection = ConfigurationManager.ConnectionStrings["kitConnection"].ConnectionString;
            SqlConnection con = new SqlConnection(projectConnection);
            con.Open();
            SqlCommand cmd = new SqlCommand("sp_search", con);
            cmd.CommandType = CommandType.StoredProcedure;

            SqlParameter param1 = new SqlParameter("@searchdata", SqlDbType.VarChar);
            cmd.Parameters.Add(param1).Value = txtbox_crud_search.Text;

            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            GridView.DataSource = ds.Tables[0];
            GridView.DataBind();
            con.Close();
        }
    }
}

Database Code for Web Form

TABLE 1 tbl_user

create table tbl_user
(
Id int identity(1,1),
User_Id varchar(50),
Name varchar(50),
Username varchar(50),
Password varchar(50)
)

LOGIN

create procedure sp_login
(
		@uname varchar(50),
		@pwd varchar(50)
)
as begin
   select count(1) from tbl_user
    where Username=@uname and Password=@pwd
end


exec sp_login 'venkat','venkat'

New Registration - INSERT

create procedure sp_newuser
( 
        @user_id varchar(50),
        @name varchar(50),
		@uname varchar(50),
		@pwd varchar(50)
)
as begin
insert into tbl_user
   (User_Id ,Name,Username,Password)
   values ( @user_id,@name,@uname,@pwd)
end

exec sp_insert 'U1001','Venkat','venkat','venkat'
exec sp_newuser 'U1002','Praveen','praveen','praveen'

TABLE 2 tbl_crud

create table tbl_crud
(
Id int identity(1,1),
Crud_Id varchar(50),
Name varchar(50),
Degree varchar(50),
Place varchar(50)
)

INSERT

create procedure sp_insert
( 
        @crud_id varchar(50),
        @name varchar(50),
		@degree varchar(50),
		@place varchar(50)
)
as begin
insert into tbl_crud
   (Crud_Id ,Name,Degree,Place)
   values ( @crud_id ,@name,@degree,@place)
end


exec sp_insert 'C1001','Asha','MCA','Chennai'

UPDATE

create procedure sp_update
(
        @crud_id varchar(100),
        @name varchar(100),
		@degree varchar(100),
		@place varchar(100)
)
as begin
update tbl_crud set Crud_Id=@crud_id,
	Name=  @name,
	Degree= @degree ,
	Place = @place where Crud_Id =@crud_id
end

exec sp_update 'C1001','Asha','MCA','Thiruvalluvar'

DELETE

create procedure sp_delete
(
        @crud_id varchar(100)
)
as begin
delete from tbl_crud where Crud_Id =@crud_id
end

exec sp_delete 'C1001'

SELECT

create procedure sp_fetch
as begin
select * from tbl_crud
end

exec sp_fetch
 

SEARCH

create procedure sp_search
(
        @searchdata varchar(100)
)
as begin
select * from tbl_crud where Name like'%'+ @searchdata+'%'
end

exec  sp_search 'sh'
 

Related Searches to Asp.Net Projects with Source Code