2005-05-17, 03:02 AM
heres some, i started workign on a db editing tool, havent gotten around to finishing it yet, at the moment it only works for actors.
reader.GetValue(5) is just the column number of the image. then just use picBox.Image = image;
and to store an image use
heres the ImageToByteArray() method
Code:
OleDbCommand command = new OleDbCommand("SELECT * FROM ActorInfo ORDER BY ActorName",conn);
OleDbDataReader reader = command.ExecuteReader();
while(reader.Read()){
Image poster = null;
try
{
byte[] bytes = (byte[])reader.GetValue(5);
if(bytes != null)
{
MemoryStream stream = new MemoryStream(bytes);
poster = Image.FromStream(stream);
}
}
and to store an image use
Code:
System.Data.OleDb.OleDbCommand command = new System.Data.OleDb.OleDbCommand();
OleDbConnection conn = new OleDbConnection(connstring);
conn.Open();
command.CommandText = "UPDATE ActorInfo SET ActorPhoto=? WHERE ActorURL=?";
command.Connection = conn;
command.Prepare();
command.Parameters.Add("ActorPhoto", System.Data.OleDb.OleDbType.Binary);
command.Parameters.Add("ActorURL", System.Data.OleDb.OleDbType.VarChar);
command.Parameters[0].Value = ImageToByteArray((Image)HeadShot.Clone());
command.Parameters[1].Value = ActorURL;
command.ExecuteNonQuery();
conn.Close();
heres the ImageToByteArray() method
Code:
internal byte[] ImageToByteArray(Image image)
{
using(image)
{
MemoryStream stream = new MemoryStream();
image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
return stream.ToArray();
}
}