I am having some problems with my mini-project.
I have to check if the name and password in the TextBox text field match the SQL database. If the password and name match the database, the user will be transferred over to another form. Otherwise, it will display an error message.
Right now. I can’t determine whether the name and password entered in the TextBox text matches the SQL Database.
I am not using Data Binding for this project; this is just a normal database application.
private void button2_Click(object sender, EventArgs e)
{
if (PasswordtextBox1.Text == "")
{
MessageBox.Show("Error! Enter password !", "Warning");
}
else
{
if (StaffUserIDcomboBox1.Text == "")
{
MessageBox.Show("Warning!");
}
string strSql = "Select UserLogin From UserLogin Where UserLoginID=" + int.Parse(StaffUserIDcomboBox1.Text);
UserClass1 userClass = new UserClass1();
SqlDataReader UserLogin_ID = userClass.GetUserID();
userClass.executeDataCommand(strSql);
int rowCount = 0;
if (UserLogin_ID.HasRows)
{
while (UserLogin_ID.Read())
{
rowCount++;
}
DisplayLabel.Text = rowCount.ToString();
UserLogin_ID.Close();
//pass value to form2 if valid
string userid = StaffUserIDcomboBox1.Text;
parent.setCurentUser(userid);
}
else
{
MessageBox.Show("No Results Found! Please Try again!");
}
}
}
I could not locate any code that checks for the password match in the database. Generally you should have a method that validate the user along with the password like