Hello everyone, help make the right query to the database so that it compares that the username and password are entered correctly. I have a code.

cmd.CommandText = "SELECT * FROM t_user WHERE pass =" + pass + "and username=" + username; 

But it does not work :(

Here is the database itself

alt text

  • what does not mean? falls with an error? try adding + ";" at the end - AlexDenisov

1 answer 1

In quotes you need to substitute the login and password and separate the word and from the password ... Ie

 cmd.CommandText = "SELECT * FROM t_user WHERE pass = '" + pass + "' and username= '" + username +"'"; 

In general, for the future, cmd.CommandText somewhere on the screen and if you do not see the syntax error, then copy this query, for example, into the MySql console and it will say everything for you ...

  • And can you also say how you can programmatically increase the value of the balance column, for which the value will be specified in the variable (in the program)? For example, int balance = 5; cmd.CommandText = "UPDATE t_user SET balance +" + balance + ";"; Something like that. - Angus123
  • That's right, but just a little more difficult)) UPDATE t_user SET balance = balance + 5 WHERE ID = 1 SQL is a very simple language, if you understand it ... Write how your RPG will be ready if you don’t forget) )) g-alex91 & mail.ru - Dobby007
  • Thank you :) But this is not a game .. this is just a database with this name, I want to do auto-surfing =) But if I do not forget, I will write ... - Angus123
  • Is it possible in C #? :) - Angus123 5:41 pm
  • and do not forget the baby Bobby Teables ) - Nofate