To save a BD photo, one of the means I know, is to transform the photo into an Array of byte
, for this I use the method below:
if (Pic.Image != null)
{
using (MemoryStream stream = new MemoryStream())
{
Pic.Image.Save(stream, ImageFormat.Jpeg);
byte[] Bfoto = stream.ToArray();
Classes.Cadastro.Crm.Analise_CRM Cad_Foto = new Classes.Cadastro.Crm.Analise_CRM();
Cad_Foto.Cad_Foto_Anal_Crm(textEdit8.Text, Bfoto, Pic.Name, Pic.Properties.ZoomPercent);
}
Pic.Image.Dispose();
Pic.Image = null;
}
Now, in the database, use [varbinary]
in the column where you save the photos:
CREATE TABLE [dbo].[Crm_Fotos]
(
[id] [int] IDENTITY(1,1) NOT NULL,
[Bfoto] [varbinary](max) NULL,
[item] [varchar](150) NULL,
[foto_seq] [varchar](200) NULL
(
Ai just pass the parameter like any other data, only difference is using:
cmd.Parameters.Add("@Bfoto", SqlDbType.VarBinary).Value = Bfoto;
Questions with answers that can help:
To return multiple rows with sql Server byte array
Convert and save photo in BD
It is wrong to write byte of images in the database?
Daniel, it is not necessary to inform language in the title, the tag already identifies the language in your question.
– user28595
OK. You don’t happen to know how to help me with this problem?
– Daniel Sousa
@Danielsousa, I believe Thomas' answer will solve your problem. But it’s a tip here that not always this is a good solution.
– George Wurthmann
@Georgewurthmann very interesting, thank you for supplementing the reply
– Thomas Erich Pimentel