In this blog, we will learn how to create a Login Page Using the Stored Procedure.
Stored Procedure
CREATE PROCEDURE login_pro
(
@UserName VARCHAR(50),
@Password VARCHAR(50)
)
AS
BEGIN
DECLARE @status INT
IF EXISTS(SELECT * FROM Login WHERE UserName = @UserName AND Password = @Password)
SET @status = 1
ELSE
SET @status = 0
SELECT @status
END
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Login_Page_Using_Stored_Procedure._Default" %>
<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Name" Font-Bold="True" Width="100px" BackColor="#FFFF66" ForeColor="#FF3300"></asp:Label>
<asp:TextBox ID="TextBox_user_name" runat="server" ForeColor="#993300" Width="100px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox_user_name" ErrorMessage="Please enter username"></asp:RequiredFieldValidator>
<br />
<asp:Label ID="Label2" runat="server" Text="Password" Font-Bold="True" Width="100px" BackColor="#FFFF66" ForeColor="#FF3300"></asp:Label>
<asp:TextBox ID="TextBox_password" runat="server" ForeColor="#CC6600" TextMode="Password" Width="100px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBox_password" ErrorMessage="Please enter password"></asp:RequiredFieldValidator>
<br />
<asp:Button ID="btn_login" runat="server" Text="Login" Font-Bold="True" BackColor="#CCFF99" onclick="btn_login_Click" />
<br />
<asp:Label ID="lblmessage" runat="server" Font-Bold="True" ForeColor="#FF3300"></asp:Label>
<br />
</div>
</form>
</body>
</html>
Default.aspx.cs

Vikash TiwariPosted Jan 17, 2017, 9:43 AM
Hello!!!Very helpful post indeed!! however i'm facing a problem with the ExecuteScalar() method. Is there possibly another method we could use to retrieve the data we want?? Thank you!!
Zarifa Al GiousefPosted Mar 22, 2013, 8:34 AM
Hello!!!Very helpful post indeed!! however i'm facing a problem with the ExecuteScalar() method. Is there possibly another method we could use to retrieve the data we want?? Thank you!!
Amit PatelPosted Jun 15, 2012, 7:50 AM
If you SQL membership then no need to single lines of code.