I am new to .net please help me.
I need to create session based on the user login form. need to store loginID into session
store procedure
--------------------------------
CREATE PROCEDURE [dbo].[usp_USER_Login]
@UserID varchar(100),
@Password varchar(100)
AS
BEGIN
SELECT LoginID FROM tbl_registration WHERE UserID = @UserID AND [Password] = @Password
END
GO
c# coding
----------------------------------
protected void btnLogin_Click(object sender, EventArgs e)
{
RegistrationDO regLogin = new RegistrationDO();
string userID = txtUserID.Text;
string password = txtPassword.Text;
if (!string.IsNullOrEmpty(userID) && !string.IsNullOrEmpty(password))
{
RegistrationDO loginDO = new RegistrationDO();
loginDO.UserID = userID;
loginDO.Password = password;
bool result = RegistrationDAL.CheckUserLogin(loginDO);
if (result)
Response.Redirect("~/success.aspx");
else
lblMessage.Text = "Failed";
}
}
DataAccess Code
-----------------------------------------------
public static bool CheckUserLogin(RegistrationDO regDO)
{
SqlConnection connec = new SqlConnection(ConfigurationManager.AppSettings["SQL"]);
SqlCommand cmd = null;
DataTable dt = null;
bool RetVal = false;
try
{
conn.Open();
cmd = new SqlCommand("usp_USER_Login", connec);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@UserID",regDO.UserID));
cmd.Parameters.Add(new SqlParameter("@Password", regDO.Password));
int i = Convert.ToInt32(cmd.ExecuteScalar());
if (i > 0)
RetVal = true;
}
catch(Exception ex)
{
RetVal = false;
}
finally
{
if (conn.State == ConnectionState.Open)
conn.Close();
}
return RetVal;
}