The following code is available:

string Connect = "server=localhost;uid=admin;password=admin;persistsecurityinfo=True;database=test_database"; string CommandText = "SELECT Count(*) FROM login WHERE login = '" + textBox1.Text + "' AND password = '" + textBox2.Text + "' LIMIT 1"; MySqlConnection myConnection = new MySqlConnection(Connect); MySqlCommand myCommand = new MySqlCommand(CommandText, myConnection); myConnection.Open();**//я не понял что тут писать?** myCommand.ExecuteNonQuery();**//и тут тоже?** MySqlDataAdapter dataAdapter = new MySqlDataAdapter(myCommand); DataTable dt = new DataTable(); dataAdapter.Fill(dt); if (dt.Rows[0][0].ToString() == "1") { this.Hide(); disp dp = new disp(); dp.Show(); } else { MessageBox.Show("Пожалуйста, проверьте правильность введенных данных!"); } 

Error on line: myCommand.ExecuteNonQuery() :

MySql.Data.MySqlClient.MySqlException: "Unknown column 'password' in 'where clause'"

How to fix it?

  • You don’t need to write anything in the Open method; it simply opens the connection. And the ExecuteNonQuery method executes an SQL for the established connection and returns the number of rows involved in the instruction. It's not entirely clear what your question is. - Denis Bubnov
  • I tried but VS produces an error and points to myConnection.Open (); - beginneroot
  • It does not swear when it is started, and it is interpreted during the verification of the login and password - beginneroot
  • MySql.Data.MySqlClient.MySqlException: "Unknown column 'password' in 'where clause'" error on myCommand.ExecuteNonQuery (); - beginneroot

1 answer 1

Look at your SQL :

 SELECT Count(*) FROM login WHERE login = '" + textBox1.Text + "' AND password = '" + textBox2.Text + "' LIMIT 1 

Select the number from the login table where the field (column) login is equal to the text from textBox1.Text and the field (column) password is equal to the text from textBox2.Text .

Make sure the login table name is valid and it really exists. As well as the column names login and password also valid and these columns are in the specified table.

Mistake:

MySql.Data.MySqlClient.MySqlException: "Unknown column 'password' in 'where clause'"

indicates that the specified password column is missing in the target table, in your case in the login table. Check carefully the login table, if there is a password column there, maybe there is a name with one letter s like this: pasword .

  • And maybe so that string does not see the database: string Connect = "server = localhost; since I use openserver and do I need to write IP ??? - beginneroot
  • @beginneroot, the error text indicates a specific problem. Check the login table, if there is a password column, maybe there is a name with one letter s like this: pasword - Denis Bubnov
  • you beat absolutely right I missed one letter in the password, wrote: passwrd! Thank you very much!!! - beginneroot
  • @beginneroot If the answer helped solve your problem, then you can mark it as 'Correct', tick the answer. - Denis Bubnov