读sql server 2000中的图片,显示在picturebox中,如何做?(好多以前的贴子说的都不行)
代码如下:
string sql;
sql = "Initial Catalog=Northwind;Data Source=localhost;Integrated Security=SSPI;";
SqlConnection conn = new SqlConnection(sql);
conn.Open();
string strCmd = String.Format("SELECT photo FROM employees WHERE employeeid = {0}",1);
SqlCommand cmd = new SqlCommand(strCmd, conn);
byte[] b = (byte[])cmd.ExecuteScalar();
if ( b.Length > 0)
{
System.IO.MemoryStream stream = new System.IO.MemoryStream(b, true);
stream.Write(b, 0, b.Length);
Bitmap bmp = new Bitmap(stream);
if( bmp.Width > 500 || bmp.Height > 300)
{
Bitmap bmp1 = new Bitmap(bmp, new Size(500,300));
pictureBox1.Image = bmp1;
}
else
pictureBox1.Image = bmp;
stream.Close();
出错提示:使用了无效参数。
错误位置:Bitmap bmp = new Bitmap(stream);
何解?
http://www.codeproject.com/cs/database/albumviewer.asp