[99,分]如何读出数据库里的image字段
上传关键代码
protected System.Web.UI.HtmlControls.HtmlInputFile img;
protected System.Web.UI.WebControls.Button Button1;
......
Int32 len = 0; //length of the upload file
string ctype = string.Empty;//type of the upload file
string sql = string.Empty;
System.Web.HttpPostedFile pf = img.PostedFile;
len = pf.ContentLength;
ctype = pf.ContentType;
Stream stre = pf.InputStream;
byte[] streBt = new byte[len];
sql = "insert into testimagestore(imagedata,imagecontenttype,imagesize) values"+
"(@idata,@itype,@isize)";
SqlParameter pData = new SqlParameter("@idata",SqlDbType.Binary,len);
pData.Value = streBt;
SqlParameter pType = new SqlParameter("@itype",SqlDbType.VarChar,50);
pType.Value = ctype;
SqlParameter pSize = new SqlParameter("@isize",SqlDbType.BigInt);
pSize.Value = len;
XWeb.SqlServerDAL.SqlFunction.CmExecuteOpen(BaseCls.Conn(),
new SqlParameter[]{pData,pType,pSize},sql,CommandType.Text);
=====================================
showimg.aspx
图片显示关键代码
......
DataTable dt = XWeb.SqlServerDAL.SqlFunction.DSExecuteOpen(BaseCls.Conn(),
new SqlParameter[]{pid},sql,CommandType.Text).Tables[0];
if(dt.Rows.Count>0)
{
Response.Clear();
Response.ContentType = (string)dt.Rows[0]["imagecontenttype"];
Response.BinaryWrite((byte[])dt.Rows[0]["imagedata"]);
//Response.OutputStream.Write((byte[])dt.Rows[0]["imagedata"],0,int.Parse(dt.Rows[0]["imagesize"].ToString()));
Response.End();
}
为什么我打开http://showimage.aspx?id=1得不到图片显示出来,
急急急!!!