我正在使用以下代码将图片框图像保存到数据库。只是我需要一些代码来将图片框图像从数据库加载到图片框。
DialogResult dr = openFileDialog1.ShowDialog();
switch (dr)
{
case DialogResult.Cancel:
break;
case DialogResult.OK:
pictureBox1.Image = Image.FromFile(openFileDialog1.FileName);
sql = new SqlConnection(@"Data Source=PC-PC\PC;Initial Catalog=Test;Integrated Security=True");
cmd = new SqlCommand();
cmd.Connection = sql;
cmd.CommandText = ("insert [Entry] ([Image]) values (@Image)");
MemoryStream stream = new MemoryStream();
pictureBox1.Image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] image = stream.ToArray();
cmd.Parameters.AddWithValue("@Image", image);
try
{
sql.Open();
cmd.ExecuteNonQuery();
}
finally
{
sql.Close();
}
break;