The problem occurs because you are not writing the contents of the file correctly.
By its code, the Attachment property of the AnexoBLL class is of type byte [] . At the point in the code you create the SQL string that will be executed in the database, you are simply concatenating the byte property [] with a string. This will not cause the property value to be used, but the framework will internally use the .ToString () method of type byte [], which will return the type name. Soon your query would look something like:
insert into tb_anexo (nome_arquivo, anexo) values ('imagem.jpg', 'System.Byte[]')
Correct would be the use of parameters, not only for the code to work, but because it is a good practice and avoids even SQL injection problems. To enter, use the code as follows (adapt to use your connection):
Npgsql.NpgsqlCommand command = new Npgsql.NpgsqlCommand();
command.CommandText = "insert into tb_anexo (nome_arquivo, anexo) values (:nome_arquivo, :anexo)";
command.Parameters.AddWithValue("nome_arquivo", anexo.NomeArquivo);
command.Parameters.AddWithValue("anexo",NpgsqlDbType.Bytea, anexo.Arquivo);
command.ExecuteNonQuery();
I'm assuming you're using the correct type in your column, which in this case should be bytea (see more at
18.04.2015 / 21:57