Wednesday, 22 February 2017

code for registration form in dotnet using stored procedures

Registration form in dotnet using stored procedure

Hi friends here I'm giving step by step procedure to insert data into registration form using stored procedures in dotnet
step1:  create a table 
step2:  create a stored procedure
step3:  set web.config file
step4:  design registration form in visual studio 
step5:  write code
step6:debugging and result

Sql Code for Stored Procedure to insert data into table

USE [ravi]
GO
/****** Object:  StoredProcedure [dbo].[sp_insertintoregiser]    Script Date: 02/23/2017 12:03:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[sp_insertintoregiser]
@name varchar(20),
@username varchar(20),
@password varchar(20),
@phone bigint
as begin
insert into register(name,username,password,phone)values(@name,@username,@password,@phone)

end


web.config file:

<configuration>
<connectionStrings>
<add name="dbcs" connectionString="data source=hp-PC;database=ravi;integrated security=true;" providerName="System.Data.SqlClient"/>
</connectionStrings>

Source Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="register.aspx.cs" Inherits="register" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .style1
        {
            width: 100%;
        }
        .style2
        {
            color: #009933;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div class="style2">
    
        <strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
        Registration from</strong></div>
    <table class="style1">
        <tr>
            <td>
                name</td>
            <td>
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            </td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td>
                username</td>
            <td>
                <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
            </td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td>
                password</td>
            <td>
                <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
            </td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td>
                phone</td>
            <td>
                <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
            </td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td>
                &nbsp;</td>
            <td>
                &nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td>
                &nbsp;</td>
            <td>
                <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Submit" />
            </td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td>
                &nbsp;</td>
            <td>
                <asp:Label ID="Label1" runat="server" Text="lblmessage"></asp:Label>
            </td>
            <td>
                &nbsp;</td>
        </tr>
    </table>
    </form>
</body>

</html>

Screenshot: registration form






Business logic code:

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;

public partial class register : System.Web.UI.Page
{
    string constr = ConfigurationManager.ConnectionStrings["dbcs"].ConnectionString;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        using (SqlConnection con = new SqlConnection(constr))
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "sp_insertintoregiser";
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@name", SqlDbType.VarChar).Value = TextBox1.Text.Trim();
            cmd.Parameters.Add("@username", SqlDbType.VarChar).Value = TextBox2.Text.Trim();
            cmd.Parameters.Add("@password", SqlDbType.VarChar).Value = TextBox3.Text.Trim();
            cmd.Parameters.Add("@phone", SqlDbType.VarChar).Value = TextBox4.Text.Trim();
            cmd.Connection = con;
            con.Open();
            cmd.ExecuteNonQuery();
            Label1.Text = "data inserted successfully";

        }
    }
}

Result/output screenshot:

Thank you friends...... if you have any doubts please comment below
Ravi Kumar
9505216182
Hyderabad
India.


Here you can watch the youtube video to understand clearly



3 comments:

  1. using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;

    ///
    /// Summary description for Business
    ///
    public class Business
    {
    Data objData = new Data();
    public int Paid { get; set; }
    public int Dues { get; set; }
    public int NoOfAccounts { get; set; }
    public int ExpiryInTwoMonths { get; set; }
    public Business()
    {
    //
    // TODO: Add constructor logic here
    //
    }

    public int PaidData
    {
    get {
    return Paid;
    }

    set {
    Paid = value;
    }
    }
    public int DuesData
    {
    get {
    return Dues;
    }
    set
    {
    Dues = value;
    }
    }
    public int NoOfAccountsData
    {
    get
    {
    return NoOfAccounts;
    }
    set
    {
    NoOfAccounts = value;
    }
    }
    public int ExpiryInTwoMonthsdata
    {
    get
    {
    return ExpiryInTwoMonths;
    }
    set
    {
    ExpiryInTwoMonths = value;
    }
    }
    //public void dispay()
    //{
    //objData.Dues();
    //objData.Expiry_TwoMoths();
    //objData.Total_NoOfAccounts();
    //objData.Total_NoOfAccounts();
    //}
    }

    ReplyDelete
  2. using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Data;
    using System.Data.SqlClient;
    using System.Configuration;

    ///
    /// Summary description for Data
    ///
    public class Data
    {
    string constr = ConfigurationManager.ConnectionStrings["CONN"].ConnectionString;
    public Data()
    {
    //
    // TODO: Add constructor logic here
    //
    }
    public DataTable total_paid()
    {
    SqlConnection con = new SqlConnection(constr);
    SqlCommand cmd = new SqlCommand();
    cmd.CommandText = "Proc_PaidPayments";
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Connection = con;
    DataSet ds = new DataSet();
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    da.Fill(ds);
    DataTable dt = ds.Tables[0];
    return dt;
    }
    public DataTable Dues()
    {
    SqlConnection con = new SqlConnection(constr);
    SqlCommand cmd = new SqlCommand();
    cmd.CommandText = "Proc_Dues";
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Connection = con;
    DataSet ds = new DataSet();
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    da.Fill(ds);
    DataTable dt2 = ds.Tables[0];
    return dt2;
    //con.Open();
    //cmd.ExecuteReader();
    //con.Close();
    }
    public DataTable Total_NoOfAccounts()
    {
    SqlConnection con = new SqlConnection(constr);
    SqlCommand cmd = new SqlCommand();
    cmd.CommandText = "Proc_Totalpaid";
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Connection = con;
    DataSet ds = new DataSet();
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    da.Fill(ds);
    DataTable dt3 = ds.Tables[0];
    return dt3;
    //con.Open();
    //cmd.ExecuteReader();
    //con.Close();
    }
    public DataTable Expiry_TwoMoths()
    {
    SqlConnection con = new SqlConnection(constr);
    SqlCommand cmd = new SqlCommand();
    cmd.CommandText = "USP_GetInvestmentExpirydateInTwoMonths";
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Connection = con;
    DataSet ds = new DataSet();
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    da.Fill(ds);
    DataTable dt4 = ds.Tables[0];
    return dt4;
    //con.Open();
    //cmd.ExecuteReader();
    //con.Close();
    }

    }

    ReplyDelete
  3. nice video thank you

    ReplyDelete