Retrieve Image from ACESS database

Jan 31 2017 2:21 PM
Hello,
 
I'm using the following code to insert image in a database as byte[]

Insert code:
 
instSQL = "INSERT INTO img (Imagem,nome)VALUES('" + convImagemBinario(picBox.Image) + "','" + nomeFicheiro + "')";
OleDbConnection minhaLigacao = new OleDbConnection(ligacao);
OleDbCommand comando = new OleDbCommand(instSQL, minhaLigacao);
minhaLigacao.Open();
comando.ExecuteNonQuery();
minhaLigacao.Close();
 
the conImageBinario method:
converts image to byte[]

byte[] convImagemBinario(Image img)
{
using (MemoryStream ms = new MemoryStream())
{
img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
return ms.ToArray();
}
}
 
Load Code method:

oleDbLigacao = new OleDbConnection(ligacao);
oleDbLigacao.Open();
meusDados = new DataSet();
instSQL = "SELECT * FROM Img";
oleDbDataAdapter = new OleDbDataAdapter(instSQL, oleDbLigacao);
oleDbDataAdapter.SelectCommand.CommandText = instSQL;
oleDbComando = new OleDbCommandBuilder(oleDbDataAdapter);
oleDbDataAdapter.Fill(meusDados, "dtDados");
oleDbLigacao.Close();
 
Untill here everything is fine...

Here's the problem, i retrieve the byte array from access but i don't know how to convert that in image! I can access de column this way:

meusDados.Tables["dtDados"].Rows[Index][column]

i can only convert to string....i tried to convert to byte[] but i can´t!!


any idea?? Overall i want to save the image in byte and return the image using c# OLEDB!

Answers (2)