将字节转换为图像c#时参数无效

时间:2015-05-28 15:10:58

标签: c# sql-server image window memorystream

我已经将图像插入数据库并且数据类型是图像,但是当我想要检索它时,它非常困难并且错误将显示参数无效。

public void RetrieveImage()
  {
   var con = new SqlConnection(Connection.CATAS_LOCAL());
   string SQL = "Select Name,Image from dbo.[TestImage] where Name = 'Test1'";
   var cmd = new SqlCommand(SQL, con);
   con.Open();
   SqlDataReader Reader = cmd.ExecuteReader();
   Reader.Read();
   if (Reader.HasRows)
      {
       txtAddStaffNric.Text = Reader[0].ToString();
       byte[] img = (byte[])(Reader[1]);
       MemoryStream ms = new MemoryStream(img);
       pictureBox2.Image = Image.FromStream(ms);  ** error show at this line
      }
  con.Close();
  }

0 个答案:

没有答案