TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Rogerio Figueiredo
NA
8
0
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!
Reply
Answers (
2
)
Could not load dll
ADO.NET is returning wrong length of the columns