日期:2014-05-18  浏览次数:20763 次

怎么把数据库中的一张数据表中的图片字段里的2进制转换成图片放到picturebox里?
怎么把数据库中的一张数据表中的图片字段里的2进制转换成图片放到picturebox里?
C# code

string tmp=treeView1.SelectedNode.Text;
            SqlDataReader read = Connect.Getdataread("select * from Employees");
            while (read.Read())
            {
                if (tmp == read.GetString(1).ToString()+' ' + read.GetString(2).ToString())
                {
                    textBox1.Text = read.GetInt32(0).ToString();
                    textBox2.Text = read.GetString(1).ToString() + read.GetString(2).ToString();
                    textBox3.Text = read.GetString(3).ToString();
                    textBox4.Text = read.GetString(7).ToString();
                    MemoryStream ms=new MemoryStream(read.GetBytes(14));
                    Image img = Image.FromStream(ms);
                    pictureBox1.Image = img;
                }
            }



------解决方案--------------------
http://topic.csdn.net/u/20111107/17/49f5b567-9202-4514-a9fa-64b41148fe13.html 读取二进制流后转为图片在pictureBox显示

http://blog.csdn.net/qinleiji/article/details/5961812 把图片转成二进制证picturebox控件读取 

参考
------解决方案--------------------
C# code

String sql = "select * from picture where [id]=2";
            string str = "server=DA5A491B3F7544B;database=study;uid=sa;pwd=liyi123";
            SqlConnection con = new SqlConnection(str);
            con.Open();
            SqlCommand cmd=new SqlCommand(sql,con);
            SqlDataReader sdr = cmd.ExecuteReader();
            if(sdr.HasRows)
            {
                sdr.Read();
                byte[] bytes = (byte[]) sdr["pic"];
                MemoryStream ms =new MemoryStream(bytes);
                Image image = Image.FromStream(ms);
                pictureBox1.Image = image;
            }
            sdr.Close();
            con.Close();