8
I have a table with 2 columns in phpmyadmin,I can connect and read one column but not the other, from the following error
An unhandled Exception of type 'Mysql.Data.Mysqlclient.Mysqlexception' occurred in Mysql.Data.dll
Additional information: Unknown column '(Name I search)' in 'Where clause'
MySqlConnection conectar = new MySqlConnection(conex);
MySqlCommand command = conectar.CreateCommand();
command.CommandText = "SELECT id from hackers where Nick= "+textBox1.Text;
try{
conectar.Open();
MessageBox.Show("Conexão estabelecida!!");
}
catch (Exception ex)
{ MessageBox.Show(ex.Message); }
MySqlDataReader reader = command.ExecuteReader();
while(reader.Read())
{ label1.Text = reader["nick"].ToString(); }
conectar.Close();
}
When I use SELECT NICK FROM HACKERS WHERE id=x works but otherwise not
Try to use parameters,
command.CommandText = "SELECT id from hackers where Nick = @Nick";
.– gato
My guess is that you forgot the simple quotes '' something like "SELECT id from hackers Where Nick= '"+textBox1.Text+"'";
– Diego Filipe Pedro Santos
Face the answer is much like this here
– Marco Souza
Check how the column is written Nick, from what I saw on select is NICK, try to put it like this.
– Sergio Camillo Jr