TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Inderjeet Kaur
NA
24
3.2k
Why code return false value when username and password are correct?
Apr 8 2021 4:11 AM
class Student : DbConnection
{
public string stud_Username { set; get; }
public string stud_Password { set; get; }
public bool verify_User()
{
connectDb.Open();
SqlDataReader rd;
bool check = false;
using (var cmd = new SqlCommand())
{
cmd.CommandText = "SELECT * FROM stud_Login_Table WHERE Username=@user AND Password=@pass";
cmd.CommandType = CommandType.Text;
cmd.Connection = connectDb;
cmd.Parameters.Add("@user", SqlDbType.VarChar).Value = stud_Username;
cmd.Parameters.Add("@pass", SqlDbType.VarChar).Value = stud_Password;
rd = cmd.ExecuteReader();
while (rd.Read())
{
MessageBox.Show("Connected to database..");
}
connectDb.Close();
}
return check;
}
DbConnection conn = new DbConnection();
Student stud = new Student();
private void loginButton_Click(object sender, EventArgs e)
{
stud.stud_Username= studUser.Text;
stud.stud_Password = studPass.Text;
bool verify = stud.verify_User();
if (verify==true)
{
MessageBox.Show(" Logged in ");
Home home = new Home();
home.Show();
this.Hide();
}
else
{
MessageBox.Show("Check your Username and password !!");
}
Reply
Answers (
2
)
Syntax error near Transaction
How to type in Hindi on textbox in asp.net web or mvc application