ASPX PAGE:

<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”Default.aspx.cs” Inherits=”_Default” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&gt;

<html xmlns=”http://www.w3.org/1999/xhtml”&gt;
<head runat=”server”>
    <title></title>
</head>
<body>
    <form id=”form1″ runat=”server”>
    <div>
        <asp:Label ID=”Label1″ runat=”server” Text=”User Name”></asp:Label>
<asp:TextBox ID=”UserNameTextBox” runat=”server”></asp:TextBox>
        <br />
        <asp:Label ID=”Label2″ runat=”server” Text=”Password”></asp:Label>
        <asp:TextBox ID=”PasswordTextBox” runat=”server”></asp:TextBox>
        <br />
        <br />
        <asp:Button ID=”SubmittButton” runat=”server” onclick=”SubmittButton_Click” Text=”Submitt” />
        <asp:Label ID=”ResultLabel” runat=”server”></asp:Label>
    </div>
    </form>
</body>
</html>

ASPX.CS PAGE:

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

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

    }
    protected void SubmittButton_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(“Server=DEEPAK-PC;Database=Practice;trusted_connection=true”);
        SqlCommand cmd = new SqlCommand(“CheckForLogin”, con);
        con.Open();
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue(“@UserName”, UserNameTextBox.Text);
        cmd.Parameters.AddWithValue(“@Password”, PasswordTextBox.Text);
        int res = Convert.ToInt32(cmd.ExecuteScalar());
        if (res == 1)
            ResultLabel.Text = “Success”;
        else
            ResultLabel.Text = “Fail”;

    }
}

DATABASE CODING:

–To create table

Create table Login
(
UserName varchar(20),
Password varchar(20)
)

–To view Table

select * from Login

–To Insert value in table

insert into Login values(‘deepak’,’DEEPAK’)

–To create procedure
create proc CheckForLogin
(@UserName varchar(20), @Password varchar(20))
as
begin
select count(*) from Login where Username=@UserName and Password=@Password
end

Advertisements