天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

c# 讀取Northwind數(shù)據(jù)庫image字段

這里值得一提的是,web控件image不像winForm控件那樣可以通過讀取二進(jìn)制流賦值給image屬性來顯示圖像。可以通過變通的方法來實(shí)現(xiàn),流行的做法是新建一個頁面專門用來顯示圖像,這里代碼直接用孟子E章前輩的(作了小修改,主要是剔除78個byte字節(jié)流來正常顯示northwind數(shù)據(jù)庫的圖片):
ReadImage.ASPx.cs
復(fù)制代碼 代碼如下:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

namespace WebApplication2
{
public partial class ReadImage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string strImageID = Request.QueryString["id"];
SqlConnection myConnection = new SqlConnection("Data Source=.;Initial Catalog=northwind;User Id=sa;Password=123456;");
SqlCommand myCommand = new SqlCommand("Select Picture from Categories Where CategoryID="
+ strImageID, myConnection);

try
{
myConnection.Open();
SqlDataReader myDataReader;
myDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
if (myDataReader.Read())
{
Response.Clear();

Response.ContentType = "image/jpeg";
byte[] b = (byte[])myDataReader["Picture"];
//下面的方法就是用來讓圖片可以正常顯示
byte[] temp=new byte [b.Length -78];
Array.Copy(b, 78, temp, 0, b.Length - 78);
Response.BinaryWrite(temp);
}
myConnection.Close();
}
catch (SqlException SQLexc)
{
Response.Write(SQLexc.ToString ());
}
Response.End();

}
}
}

在源頁面如Default.ASPx.cs可以通過下面方法調(diào)用
復(fù)制代碼 代碼如下:
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack )
Image1.ImageUrl = FormatURL("1");

}
protected string FormatURL(string strArgument)
{
return "ReadImage.ASPx?id=" + strArgument;
}

如果不想新建一個頁面來承載圖像,也可以使用下面的方法:(注意:下面的類是自定義的,大家看得懂這個方法就可以了)
復(fù)制代碼 代碼如下:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

namespace WebApplication2
{
public partial class ReadImage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string strImageID = Request.QueryString["id"];
SqlConnection myConnection = new SqlConnection("Data Source=.;Initial Catalog=northwind;User Id=sa;Password=123456;");
SqlCommand myCommand = new SqlCommand("Select Picture from Categories Where CategoryID="
+ strImageID, myConnection);

try
{
myConnection.Open();
SqlDataReader myDataReader;
myDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
if (myDataReader.Read())
{
Response.Clear();

Response.ContentType = "image/jpeg";
byte[] b = (byte[])myDataReader["Picture"];
byte[] temp=new byte [b.Length -78];
Array.Copy(b, 78, temp, 0, b.Length - 78);
Response.BinaryWrite(temp);
}
myConnection.Close();
}
catch (SqlException SQLexc)
{
Response.Write(SQLexc.ToString ());
}
Response.End();

}
}
}

AspNet技術(shù)c# 讀取Northwind數(shù)據(jù)庫image字段,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 99久视频只有精品2019 | 青柠在线观看视频在线高清完整 | 久久久久激情免费观看 | 国产真实露脸乱子伦 | videossexo乌克兰 | 亚洲视频中文字幕 | 色琪琪久久热在线 | 欧美人与动牲交A精品 | 岛国片免费看 | 在线视频久久只有精品第一日韩 | 中文字幕在线不卡精品视频99 | a级毛片黄免费a级毛片 | 大胸美女被吊起来解开胸罩 | 青青伊人精品 | 日日夜夜撸 在线影院 | 4399日本电影完整版在线观看免费 | 一本道高清无码v | 被同桌摸出水来了好爽的视频 | 成人国产亚洲精品A区天堂蜜臀 | 亚洲国产精品久久精品成人网站 | 中文字幕亚洲无线码一区 | 开心久久激情 | 99久久伊人一区二区yy5o99 | 97资源站超碰在线视频 | 国产在线成人一区二区三区 | 秋霞电影伦网理最新在线看片 | 国产日韩欧美有码在线视频 | 精品国产乱码久久久久久乱码 | 国产自拍视频在线一区 | 野草观看免费高清视频 | 日日射夜夜干夜夜插在线播放 | 天美传媒 免费观看 | 一个人免费播放高清在线观看 | 视频一区精品自拍亚洲 | 免费精品国产日韩热久久 | 色狠狠AV老熟女 | 性按摩AAAAAAA片 | 丰满的寡妇hd高清在线观看 | 中国videos1314tv| 国产精品卡1卡2卡三卡四 | 国产在线精品亚洲一品区 |