请问如何将二进制流从数据库里读取出来啊?
我是这样保存的
byte[] fileByte = null;
fileByte = new byte[files[0].ContentLength];
数据库里面是Image类型,
现在我要读取出来
public byte [] WJL
{
get { return _wjl; }
set { _wjl = value; }
}
//WJL = Convert.ToByte( dr["WJL"].ToString()); 这里应该怎么写啊?
[解决办法]
http://www.2cto.com/kf/201201/117016.html
[解决办法]
protected void Page_Load(object sender, EventArgs e)
{
string id = Request.Params["Id"];
DataSet ds = service.getimage(id);
if (ds.Tables[0].Rows.Count == 0)
return;
byte[] bydata = (byte[])ds.Tables[0].Rows[0][0];
Response.ClearContent();
Response.ContentType = "image/jpeg";
Response.BinaryWrite(bydata);
}
[解决办法]
/// <summary> /// 从数据库读取相应图片 /// </summary> /// <param name="name">图片名称</param> /// <returns>返回该图片</returns> public static Image GetImage(string name) { SqlConnection con = new SqlConnection(SqlConString); SqlCommand cmd = con.CreateCommand(); SqlParameter pname = new SqlParameter("@name", name); cmd.Parameters.Add(pname); cmd.CommandText = "select image from MyTable where name=@name"; con.Open(); byte[] MyData = (byte[])cmd.ExecuteScalar(); MemoryStream ms = new MemoryStream(MyData, 0, MyData.Length); ms.Seek(0, SeekOrigin.Begin); Image image = Image.FromStream(ms); con.Close(); return image; }
[解决办法]
files[0].ContentLength这个是内容吧。
byte[] data=system.io.file.read();
[解决办法]