日期:2014-05-18 浏览次数:20993 次
//... MemoryStream stream = new MemoryStream(); stream.Write(bin, 0, bin.GetUpperBound(0)); pictureBox1.Image = Bitmap.FromStream(stream); stream.Close();
------解决方案--------------------
以下代码用Northwind测试ok
SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=Northwind;User ID=sa;Password=sa");
SqlCommand myCommand = new SqlCommand("Select top 1 Picture from Categories order by CategoryID desc", conn);
try
{
conn.Open();
SqlDataReader myDataReader;
myDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
if (myDataReader.Read())
{
byte[] bin = (byte[])myDataReader["Picture"];
MemoryStream stream = new MemoryStream(bin, true);
stream.Write(bin, 0, bin.Length);
pictureBox1.BackgroundImageLayout = ImageLayout.Center;
pictureBox1.Image = Bitmap.FromStream(stream);
stream.Close();
}
conn.Close();
}
catch (SqlException SQLexc)
{
}