Hi,
Create a method called IsValidUser as like below one.
private bool IsValidUser(string userName, string passWord)
{
bool loginSuccessful = false;
string sql = "SELECT* FROM Login WHERE Username=@UserName AND [Password]=@Password'";
SqlCommand sqlCommand= new SqlCommand(sql, con);
sqlCommand.Parameters.Add(new SqlParameter("Name", userName));
sqlCommand.Parameters.Add(new SqlParameter("[Password]", passWord));
SqlDataReader rdr = mySQL.ExecuteReader();
if (rdr.HasrRows())
loginSuccessful = true;
return loginSuccessful ;
}
And use that method in Button Click event as like the below one,
private void loginbtn_Click(object sender, EventArgs e)
{
if( IsValidUser(nametxtbx.Text.Trim(),passtxtbx.Text.Trim()))
{
}
else
{
nametxtbx.Text = "";
passtxtbx.Text = "";
nametxtbx.Focus();
}
}