c# winform 读取oracle中blob字段的图片显示到pictureBox里

来源:互联网 发布:异步加载js方案 编辑:程序博客网 时间:2024/05/17 22:23

private void button1_Click(object sender, EventArgs e)

 {

   OracleConnection conn = dbc.getConnection();//获得conn连接

      try {

              //重新连接数据库

                conn.Open(); 

                OracleCommand cmd = conn.CreateCommand();

                cmd.CommandText = "select xp from user_xp where id = 12345 ";//查询获得图片流

                OracleDataReader oddr = cmd.ExecuteReader();//创建一个OracleDateReader对象

                oddr.Read();

                MemoryStream ms = new MemoryStream((byte[])oddr["xp"]);

                Image image = Image.FromStream(ms, true);

                oddr.Close();

                conn.Close();

                pictureBox1.Image = image; 

 

 

               //已经连接好数据库(根据DataGridView里的ID查找数据库里的照片,显示在picturebox里)

                // myDB = new DBTool(Conn);

               //string tt = "";

              //tt = "select xp from user_xp where picture_id='"+DataGridView.Rows[e.RowIndex].Cells[0].Value+"";        

             //OracleDataReader oddr = myDB.RunProcGetReader(tt); 

            //oddr.Read();

           //MemoryStream ms = new MemoryStream((byte[])oddr["xp"]);

          //Image image = Image.FromStream(ms, true);

         //oddr.Close();

        //myDB.Dispose();

       // pictureBox1.Image = image;

 

 

    //已经连接好数据库(直接从数据库里查找出图片,显示在picturebox里)

   //byte[] bt = (byte[])DataGridView1.Rows[e.RowIndex].Cells[0].Value;

   //Stream stream = new MemoryStream(bt); 

   //Bitmap bmp = (Bitmap)System.Drawing.Image.FromStream(stream);

   //pictureBox1.Image = bmp;

}

 catch (Exception ee)

  {

    MessageBox.Show(ee.Message.ToString());

  }

}