c# 读数据库二进制流到图片

public Bitmap PictureShow(string connectionString, string opName, string productType)
        {
            SqlConnection conn = new SqlConnection(connectionString);
            conn.Open();
            //MessageBox.Show("连接成功");
            string sqlCmd = "select 产品图片 from Tupian where 产品型号='" + productType + "' and 工位号='" + opName + "'";
            SqlCommand command = new SqlCommand(sqlCmd, conn);
            DataSet dtSet = new DataSet();
            SqlDataAdapter myDataAdapter = new SqlDataAdapter(sqlCmd, conn);
            myDataAdapter.Fill(dtSet);
            DataTable dt = dtSet.Tables[0];
            byte[] bufferByte = (byte[])dt.Rows[0]["产品图片"];//将二进制流转化成图片
            MemoryStream ms = new MemoryStream(bufferByte, true);
            ms.Write(bufferByte, 0, bufferByte.Length);
            Bitmap bmpt = new Bitmap(ms);
            return  bmpt;
        }

实现单张读取。

posted @ 2013-07-19 14:07  佳序  阅读(424)  评论(0编辑  收藏  举报