I did but still getting eror
here is my procedue
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[GetDepartments]
@Password NVARCHAR(200),
@UserName NVARCHAR(20),
@Name NVARCHAR(20),
@Id Int
AS
BEGIN
SET NOCOUNT ON;
DECLARE @UserId INT, @LastLoginDate DATETIME
SELECT @UserId = ID, @LastLoginDate = LastLogin
FROM User3 WHERE [UserName] = @Username AND [Password] = @Password
IF @UserId IS NOT NULL
BEGIN
SELECT 1 -- User available.
END
ELSE
BEGIN
SELECT -1 -- User not available.
END
END
login code
protected void OnAuthenticate(object sender, AuthenticateEventArgs e)
{
string constr = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
int UserID;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("GetDepartments"))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.CommandType = CommandType.StoredProcedure;
Session["UserName"] = ctlLogin.UserName;
Session["Name"] = ctlLogin.UserName;
Session["Id"] = Session["Id"].ToString();
cmd.Parameters.AddWithValue("@ID", ctlLogin.UserName);
cmd.Parameters.AddWithValue("@Name", ctlLogin.UserName);
cmd.Parameters.AddWithValue("@UserName", ctlLogin.UserName);
cmd.Parameters.AddWithValue("@Password", (ctlLogin.Password));
// cmd.Parameters.AddWithValue("@Phone", ctlLogin.UserName);
cmd.Connection = con;
con.Open();
UserID = Convert.ToInt32(cmd.ExecuteScalar());
con.Close();
}
switch (UserID)
{
case -1:
ctlLogin.FailureText = "Username or password not correct.";
break;
case -2:
ctlLogin.FailureText = "Account has not been activated.";
break;
case -3:
ctlLogin.FailureText = "Your Password.";
break;
default:
Response.Redirect("~/LandingPage.aspx");
break;
}
}
}
}
}
Landing page session
protected void Page_Load(object sender, EventArgs e)
{
if (Session["UserName"] == null)
// if (Session["UserName"] != null && Session["UserName"].ToString() == "micah")
{
Response.Redirect("~/Account/Login.aspx");
// PanelViewComments.
if (Session["UserName"] != null && Session["UserName"].ToString() != string.Empty)
{
string username = Session["UserName"].ToString();
Session["Id"] = Session["Id"].ToString();
// GetPost(username);
}
}