我在一个页面中用了一个datalist,其中放了一个image
在后台中谢了image.imageUrl="readPic.aspx?afterID="+id;
在readPic页面中,写了一下代码。读不出啊,大家快看看
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Drawing.Imaging;namespace adb
{
/// <summary>
/// readPic 的摘要说明。
/// </summary>
public class readPic : System.Web.UI.Page
{
adb.Access.DBConnection dbcon=new adb.Access.DBConnection();
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
string afterID=Page.Request.QueryString["afterID"];
string sql="select questionPic from AfterServices where afterID='"+afterID+"'";
SqlConnection con=dbcon.getConnection();
con.Open();
SqlCommand com=new SqlCommand(sql,con);
SqlDataReader dr=com.ExecuteReader();
while(dr.Read())
{
byte[] buffer=(byte[])dr["questionPic"];
Page.Response.Clear();
Page.Response.ContentType="image/gif";
Response.BinaryWrite(buffer);
Page.Response.End();
}
con.Close();
}
}
}
}
在后台中谢了image.imageUrl="readPic.aspx?afterID="+id;
在readPic页面中,写了一下代码。读不出啊,大家快看看
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Drawing.Imaging;namespace adb
{
/// <summary>
/// readPic 的摘要说明。
/// </summary>
public class readPic : System.Web.UI.Page
{
adb.Access.DBConnection dbcon=new adb.Access.DBConnection();
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
string afterID=Page.Request.QueryString["afterID"];
string sql="select questionPic from AfterServices where afterID='"+afterID+"'";
SqlConnection con=dbcon.getConnection();
con.Open();
SqlCommand com=new SqlCommand(sql,con);
SqlDataReader dr=com.ExecuteReader();
while(dr.Read())
{
byte[] buffer=(byte[])dr["questionPic"];
Page.Response.Clear();
Page.Response.ContentType="image/gif";
Response.BinaryWrite(buffer);
Page.Response.End();
}
con.Close();
}
}
}
}
string sql="select questionPic from AfterServices where afterID="+afterID;
readPic.aspx明明是一个网页文件,当然显不出来,换一图像文件不就行了!
例如:image.imageUrl="readPic.gif";
看看能否正常显示
{
Response.ContentType = "image/jpeg";
Response.BinaryWrite((byte[])dr["questionPic"]);
Response.End();
}
我的图片字段是image,这个不错。
我写了两个页面,一个页面,一个数据连接层。
页面里这样写。
string path=this.questionPic.PostedFile.FileName;
int size=this.questionPic.PostedFile.ContentLength;
string picType=this.questionPic.PostedFile.ContentType;
Stream picStream=this.questionPic.PostedFile.InputStream;
byte[] content=new byte[size];
int status=picStream.Read(content,0,size);然后我调用数据连接层的方法,这里写了一个存储过程图片类型也是image。但是我们给这个变量传参数时他应该是byte〔〕,对吧??我就是把content传进去的。
如果数据连接和表示页面在一个页面。它就是可以的
我怀疑是int status=picStream.Read(content,0,size);有问题,当把content直接传过去时,数据连接层,可能认为每有这句。