2
Good afternoon guys, I’m developing a small project in c# that needs to present an image together with a recipe and it is the first time I work with image in database, I already inserted the image in the database. Already in the project(C#
) when I pass the type parameter MemoryStream
of error:
Invalid parameter.
var receitaP1 = cmd.ExecuteReader();
while (receitaP1.Read())
{
receita.CodReceita = Convert.ToInt16(receitaP1["codReceita"].ToString());
receita.NomeReceita = receitaP1["nomeReceita"].ToString();
receita.ModoPreparo = receitaP1["modoDePreparo"].ToString();
receita.Tipo = receitaP1["nomeTipo"].ToString();
byte[] imagem = (byte[]) receitaP1["imagem"];
MemoryStream memoria = new MemoryStream(imagem);
Image image = Image.FromStream(memoria); //"Memoria" >>> Erro: parametro invalido!
receita.Imagem = image;
}
Check it out, it’s already position 0
can show the generated stacktrace?
– mercador
It is possible that the contents of your
byte[]
has not been saved as a valid image, then? I only see this alternative not to be working. Test convert your byte array to base64string (var b64 = Convert.ToBase64String(imagem);
) and use a online converter to confirm that the.– Diego Rafael Souza
show how you are saving the image in the bank
– Rovann Linhalis
Ready, I made the Insert from an example I picked up on the internet
– Michele Santos