login from sql server database in asp.net c#
private void button1_Click(object sender, EventArgs e)
{
// Validation for User Name
if (txtUserName.Text.Trim() == "")
{
MessageBox.Show("Please Enter User Name");
txtUserName.Focus();
return;
}
// Validation for Password
if (txtPassword.Text.Trim() == "")
{
MessageBox.Show("Please Enter Password");
txtPassword.Focus();
return;
}
SqlCommand cmd = new SqlCommand("select * from Login where User_Id ='" + txtUserName.Text + "'and Password='" + txtPassword.Text + "'", con);
SqlDataAdapter dr = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
dr.Fill(dt);
if (dt.Rows.Count > 0)
{
Response.Redirect("page.aspx");
}
else
{
lblError.Text = " Please enter correct User Name and password";
}
}
thanks for posting this code Sir.
ReplyDelete