您的位置:首页 > 数据库

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

2013-07-19 14:07 197 查看
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;
}

实现单张读取。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: