Save picturebox image in bd access with C #

0

I have a BD Access 2016 with a table that contains an OLE object field, in Visual Studio 2012 I have a WF project where I have a form that contains a pictureBox to attach the logo. I have an insert button that calls the statement made in TableAdapter .

The issue is that I'm having trouble attaching that image, I can not do it as an image or with the route, any advice?

private void button3_Click(object sender, EventArgs e)
{         
    try
    {
        int numero = Convert.ToInt32(cPEmpresaTextBox.Text);
        Bitmap BmpImage = new Bitmap(logotipoEmpresa2PictureBox.Image);
        MemoryStream Mystream = new MemoryStream();
        BmpImage.Save(Mystream,System.Drawing.Imaging.ImageFormat.Jpeg);
        byte[] ImagenBytes = Mystream.ToArray();
        tblEmpresaTableAdapter.InsertarEmpresa(nombreEmpresaTextBox.Text, cIFEmpresaTextBox.Text, direccionEmpresaTextBox.Text, numero, poblacionEmpresaTextBox.Text, provinciaEmpresaTextBox.Text, estadoEmpresaComboBox.Text, cuotaAsociacionComboBox.Text, emailEmpresaTextBox.Text, paginaWebEmpresaTextBox.Text,ImagenBytes);
        MessageBox.Show("Registro añadido");
        conexion.Close();
        tblEmpresaTableAdapter.Fill(basededatos1DataSet.tblEmpresa);
    }
    catch (Exception ex)
    {
        MessageBox.Show("Error : "+ex);
    }
}

The query works, because I managed to save the record in the bd but then I do not know what to do to recover the logo in jpg and see it well in PictureBox .

Maybe something in the event BackgroundImageChanged of PictureBox that checks if it is jpg and transform it instead?

    
asked by victorl 29.05.2016 в 12:08
source

1 answer

1

If in the table companies defined in the TableAdapter you have the byte array field that maps to the image field when you make a GetData() you would get the company id and next to it the associated image field.

Note: the "image_stream" field of the image would be your photo field.

When you have the array byte you convert it to Image to assign it to the Picturebox

public Image byteArrayToImage(byte[] byteArrayIn)
{
     MemoryStream ms = new MemoryStream(byteArrayIn);
     Image returnImage = Image.FromStream(ms);
     return returnImage;
}    

C # Image to Byte Array and Byte Array to Image Converter Class

    
answered by 31.05.2016 в 19:08