代码如下:
 String constr="data source=zss;initial catalog=ZssTest;
     password=norman;persist security info=True;user id=sa;
         workstation id=ZSS;packet size=4096";
         SqlConnection sqlcon=new SqlConnection(constr);
     String sqlselect="select bin_image,id from Table_1 where id='29'";
     SqlCommand sqlcom=new SqlCommand(sqlselect,sqlcon);
     sqlcon.Open();
     SSqlDataReader reader=sqlcom.ExecuteReader();
     reader.Read();
     //取出数据
     Byte[] bytes=(Byte[])reader["bin_image"];
     //根据生成Bitmap
         System.IO.MemoryStream ms=new System.IO.MemoryStream(bytes,0,bytes.
Length);
     Bitmap bitmap=new Bitmap(ms,true);
     //在窗口上绘制image
     Graphics g=Graphics.FromHwnd(this.Handle);
     g.DrawImage(bitmap,10,10,bitmap.Width,bitmap.Height);
     sqlcon.Close();

解决方案 »

  1.   

    我现在的问题就在这里
    Byte[] bytes=(Byte[])reader["bin_image"];
    报告说,不能实现转换。
      

  2.   

    this.sqlConnection1.Open();
    SqlCommand sqlCommand=new SqlCommand("select id,name,age,image from students",this.sqlConnection1);
    SqlDataReader sqlDataReader=sqlCommand.ExecuteReader(CommandBehavior.SequentialAccess);
    sqlDataReader.Read();
    textBoxId.Text=sqlDataReader.GetInt32(0).ToString();
    textBoxName.Text=sqlDataReader.GetString(1);
    textBoxAge.Text=sqlDataReader.GetInt32(2).ToString();
    int bufferSize=100;
    long alreadReadSize=0; 
    int readingSize;
    byte[] imageFieldValue=new byte[bufferSize];
    MemoryStream memoryStream=new MemoryStream();
    do{
    readingSize=(int)sqlDataReader.GetBytes(3,alreadReadSize,imageFieldValue,0,bufferSize);
    memoryStream.Write(imageFieldValue,0,readingSize);
    alreadReadSize+=readingSize;
    }
    while (readingSize==bufferSize);
    pictureBoxImage.Image=new Bitmap(memoryStream);
    sqlDataReader.Close();
    this.sqlConnection1.Close();
    }
    绝对好,昨晚才编的?解决问题别忘了给分