0
我正在使用以下代碼將picturebox圖像保存到數據庫。只是我需要一些代碼來將picturebox圖像從數據庫加載到picturebox。c sharp中的picturebox圖像
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;
你嘗試過這麼遠嗎?你用Google搜索了嗎?看看Image.FromSteam(Stream stream)方法。 – SimpleVar
possible dup http://stackoverflow.com/questions/7225610/i-want-to-load-image-from-the-database-into-a-picture-box-using-loadasync-and-a –