i'm develpoing a login server and i've come to this problem: I'm using this SQL function to get password where username matches:
SELECT password FROM users WHERE username='someusername';
On c# i'm using this code:
string cmdString = ("SELECT password FROM users WHERE username='@username'");
using (var con = new MySqlConnection(CNN_STRING))
{
con.Open();
var cmd = new MySqlCommand(cmdString, con);
cmd.Parameters.AddWithValue("@username", user);
return cmd.ExecuteScalar().ToString();
}
On MySQL workbench it works normally but on c# i always get a null value, and if i try to use cmd.ExecuteReader and Reader.Read() instead of cmd.ExecuteScalar() i get a exception saying that i haven't run Reader.Read() though i did.