Whenever I run the application I keep getting the error:
You have an error in your SQL syntaxt; check the manual that corresponds to your MySql server version for the right sytanx to use near 'User_Info.users where user_name= and password=
My code is:
try
{
string myConnection = "datasource=127.0.0.1;port=3306;username=root;password=welcome";
MySqlConnection myConn = new MySqlConnection(myConnection);
MySqlCommand SelectCommand = new MySqlCommand("select * User_Info.users where user_name=" + this.username_txt.Text + " and password=" + this.password_txt + " ;", myConn);
MySqlDataReader myReader;
myConn.Open();
myReader = SelectCommand.ExecuteReader();
int count = 0;
while (myReader.Read())
{
count = count + 1;
}
if (count == 1)
{
MessageBox.Show("Username and password is correct");
}
else if (count > 1)
{
MessageBox.Show("Duplciate Username and password, access is denied");
}
else
MessageBox.Show("Username and password is incorrect, please try again");
myConn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
What causes this error?