日期:2014-05-17 浏览次数:20516 次
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["byte_img"].ConnectionString);
conn.Open();
string sql = "select top 1 * from byte_img order by ID desc";
SqlDataAdapter sda = new SqlDataAdapter(sql.ToString(),conn);
DataSet ds = new DataSet();
ds.Clear();
sda.Fill(ds);
conn.Close();
DataTable dt = ds.Tables[0];
byte[] b2 = (byte[])dt.Rows[0]["ImgByte"];
string type = (string)dt.Rows[0]["ImgType"];
Response.Clear();
string Type = checktype(type);
Response.ContentType = Type;
byte[] photo = (byte[])dt.Rows[0]["ImgByte"];
Response.BinaryWrite(b2);
Response.End();
//根据文件的扩展名来获取对应的“输出流的HTTP MIME“类型
private string checktype(string type)
{
string ContentType;
switch (type)
{
case ".gif ":
ContentType = "image/gif "; break;
case ".jpg ":
ContentType = "image/jpeg "; break;
case "jpeg ":
ContentType = "image/jpeg "; break;
case ".png":
&nb