Could not find specified column in Results

Asked

Viewed 114 times

0

I have a code to search in two tables, a search the logo and the other the images, the first he does normally, does the reading and everything else, in the second he already error, the code is as follows:

using (MySqlConnection conn = GetConnection())
        {
            using (MySqlCommand command = GetCommand(conn))
            {
                command.CommandText = @"

                        SELECT
                            tb_logos.*
                        FROM tb_logos
                        WHERE tb_logos.id_logo = @id_logo

                    ;";

                command.Parameters.AddWithValue("@id_logo", id);

                using (IDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        post = Preencher(reader);
                    }
                }
                command.CommandText = @"

                        SELECT tb_logo_imagem.ds_imagem FROM tb_logo_imagem WHERE id_logo = @img_id_logo;";

                command.Parameters.AddWithValue("@img_id_logo", id);

                using (IDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        try
                        {
                            post.Imagens.Add(reader["tb_logo_imagem.ds_imagem"].ToString());
                        }
                        catch (Exception e)
                        {
                            post.Imagens = null;
                        }
                    }
                }
            }
        }

It reports the following error:

Could not find specified column in Results

And when I change the reader for reader["ds_imagem"] he informs this other error:

Undefined object reference for an object instance.

I ran the query directly in mysql and returned the result normally.

  • On which line is it wrong? What does the method Preendher(reader);? What is the structure of the table?

  • @Ronaldoaraújoalves the method inserts the bank information in the class, the error occurs in the command: post.Imagens.Add(reader["tb_logo_imagem.ds_imagem"].ToString());

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.