Create Login Page Form Example In Asp.Net

protected void btnLogIn_Click(object sender, EventArgs e)
02
{

//Create Connection String And SQL Statement

string strCon = ConfigurationManager.ConnectionStrings[“ConnectionString”].ConnectionString;

string strSelect = “SELECT COUNT(*) FROM Users WHERE UserName = @Username AND Password = @Password”;

 

SqlConnection con = new SqlConnection(strCon);

SqlCommand cmd = new SqlCommand();

cmd.Connection = con;

cmd.CommandType = CommandType.Text;

cmd.CommandText = strSelect;

 

SqlParameter username = new SqlParameter(“@Username”, SqlDbType.VarChar, 50);

username.Value = txtUserName.Text.Trim().ToString();

cmd.Parameters.Add(username);

 

SqlParameter password = new SqlParameter(“@Password”, SqlDbType.VarChar, 50);

password.Value = txtPwd.Text.Trim().ToString();

cmd.Parameters.Add(password);

 

con.Open();

int result = (Int32)cmd.ExecuteScalar();

con.Close();

 

if (result >= 1)

{

Response.Redirect(“UpdateProfile.aspx”);

}

else

lblMsg.Text = “Incorrect Username or Password”;

 

}

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir

1 × 5 =

This site uses Akismet to reduce spam. Learn how your comment data is processed.