I wanted to create a function on which a user can guess the value from a MySQL database. label2 is randomly generated by other codes, so the user will have to guess the partner value of the label2 by inputting texbox1. I try to use the usual login function for the code
s = "SELECT val2 FROM data_reader.db WHERE val1='" + this.label2.Text + "'and image='" + this.textBox1.Text + "';";
int count = 0;
while (mdr.Read())
{
count = count + 1;
}
if (count == 1)
{
MessageBox.Show("correct");
}
else
{
MessageBox.Show("wrong");
}
problem with this code is it always return wrong even when the value are correct. is there any missing algorithm or maybe my code is not suitable for this purpose?
if (count >= 1)instead of==? Why are you counting if you expect there to be only one answer? Or can there be multiple rows with the sameval1andimagevalues?sandmdr.Read()?