?? showpicture.aspx.cs
字號:
?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;
using System.Data.SqlClient;
public partial class ShowPicture:System.Web.UI.Page
{
protected void Page_Load(object sender,EventArgs e)
{ ///創建鏈接
SqlConnection myConnection = new SqlConnection(
ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString);
///定義SQL語句
string cmdText = "SELECT * FROM Pictures WHERE PictureID='1'";
///創建Command
SqlCommand myCommand = new SqlCommand(cmdText,myConnection);
///定義DataReader
SqlDataReader dr = null;
try
{ ///打開鏈接
myConnection.Open();
///讀取數據
dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
}
catch(SqlException ex)
{ ///拋出異常
throw new Exception(ex.Message,ex);
}
///定義保存數據的byte數組
byte[] Data = null;
while(dr.Read())
{ ///讀取數據
Data = (byte[])dr["Data"];
Response.ContentType = dr["Type"].ToString();
}
dr.Close();
//顯示圖片數據
this.EnableViewState = false;
///輸出文件頭
Response.AppendHeader("Content-Length",Data.Length.ToString());
///輸出文件的數據
Response.BinaryWrite(Data);
///結束輸出
Response.End();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -