所有代码如下:using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls;public partial class ImageShow : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { // 创建数据集实例 FileSet fileSet = new FileSet(); // 创建数据适配器实例 FileSetTableAdapters.UpFilesTableAdapter adapter = new FileSetTableAdapters.UpFilesTableAdapter(); // 读取数据,我们从GridView通过QueryString方式传入参数FileID,该参数是数据库中记录的文件ID adapter.Fill(fileSet.UpFiles, int.Parse(Request["FileID"])); // 取出二进制文件内容,假设文件一定存在,则第0行的FileContent字段就是我们要取的数据 byte[] by = (byte[])fileSet.UpFiles.Rows[0]["FileContent"]; // 写入输出流 Response.BinaryWrite(by); } }
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class ImageShow : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// 创建数据集实例
FileSet fileSet = new FileSet(); // 创建数据适配器实例
FileSetTableAdapters.UpFilesTableAdapter adapter = new FileSetTableAdapters.UpFilesTableAdapter(); // 读取数据,我们从GridView通过QueryString方式传入参数FileID,该参数是数据库中记录的文件ID
adapter.Fill(fileSet.UpFiles, int.Parse(Request["FileID"])); // 取出二进制文件内容,假设文件一定存在,则第0行的FileContent字段就是我们要取的数据
byte[] by = (byte[])fileSet.UpFiles.Rows[0]["FileContent"]; // 写入输出流
Response.BinaryWrite(by); }
}