使用MySQLDriverCS;进行操作
读取图片控件里面的图像
 MemoryStream bs = new MemoryStream();
  pictureBox1.Image.Save(bs, System.Drawing.Imaging.ImageFormat.Jpeg);
 sql =" insert into staff set photo_info='" + Convert.ToBase64String(bs.ToArray())+"'";//图片信息
执行完以上SQL语句后,数据里面的数据时有的,图片用的是longbole数据类型。
  但是读取则不成功
string sql = "select * from staff"DataSet staff_dataset = FCCH_HR_Database.do_select(sql);//执行查询语句 获取dataset                if (staff_dataset != null)
                {
                    for (int i = 0; i < staff_dataset.Tables[0].Rows.Count; i++)
                    {
                      object object_photo_info = staff_dataset.Tables[0].Rows[i][18];//照片信息
                      Byte[] pic_byte = (Byte[])object_photo_info;
                      System.IO.MemoryStream ms = new System.IO.MemoryStream(pic_byte);
                      pictureBox1.Image = System.Drawing.Image.FromStream(ms);
                     }
                }这样,无法显示图片,不清楚什么原因 

解决方案 »

  1.   

    直接先在MYSQL中SELECT一下数据看一下,字段中存贮的图片数据是否正确。 以判断是写入时不正确,还是无法正确记取。
      

  2.   

    数据库字段设计用blob类型;存的主要代码:
    File file = new File("E:/test.jpg"); 
    byte[] imageBytes=new byte[(int)file.length()];
          FileInputStream fis=new FileInputStream(file);
    fis.read(imageBytes);
    fis.close();
    ps.setBytes(2, imageBytes);取的主要代码:
    byte imageBytes []=null;
    imageBytes =rs.getBytes(1);
    Image image = Toolkit.getDefaultToolkit().createImage(imageBytes);