给点 思路 或者 代码 先谢谢了
新件个摸版列来显示图片,拖个Image在摸版中,取出图片地址,然后把把相应的图片地址传给Image
以二进制保存到数据库
Stream sr = File1.PostedFile.InputStream;
byte[] buffer = new byte[size];
sr.Read(buffer, 0, size);
cmd.Parameters.Add("@image", SqlDbType.Image);
cmd.Parameters["@image"].Value = buffer;
...
GridView模版列中
<asp:Image ID="Image2" AlternateText=<%# Eval("ID") %> ImageUrl='<%# "~/OK/showimage.aspx?id="+Eval("ID") %>' runat="server"/>
(页面showimage.aspx显示图片)
protected void Page_Load(object sender, EventArgs e)
{
string id = Request.QueryString["ID"];
string conStr = "Database=FILE;Server=.;Integrated Security=SSPI;";
if (id != null && id != "")
{
try
{
SqlConnection con = new SqlConnection(conStr);
con.Open();
SqlCommand cmd = new SqlCommand("select * from Image where ID=@ID", con);
cmd.Parameters.Add(new SqlParameter("@ID", id));
SqlDataReader dr = cmd.ExecuteReader();
dr.Read();
Response.ContentType = "Image/Jpeg";
Response.AddHeader("Content-Dispositon", "attachment;filename=" + dr["name"].ToString());
Response.AddHeader("Content-Length", dr["size"].ToString());
int size=Convert.ToInt32( dr["size"]);
byte[] buffer=new byte[size];
dr.GetBytes(4,0,buffer,0,size);
Response.BinaryWrite(buffer);
con.Close();
}
catch (Exception ex)
{
throw ex;
}
}
}