欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

asp.net 圖片的讀寫入庫實現(xiàn)代碼

 更新時間:2009年11月12日 21:43:45   作者:  
asp.net對圖片的讀寫,實現(xiàn)將圖片保存到數(shù)據(jù)庫中,然后再讀取顯示的實現(xiàn)代碼。
寫圖片c:\1.jpg到表cinfo中
復(fù)制代碼 代碼如下:

private static void AddCinfo()
{
string strSql = "insert into cinfo (srvtitle,csttitle,introduction,logo) values

(@srvtitle,@csttitle,@introduction,@logo)";
SqlParameter[] parms =
{
new SqlParameter("@srvtitle",SqlDbType.VarChar,30),
new SqlParameter("@csttitle",SqlDbType.VarChar,30),
new SqlParameter("@introduction",SqlDbType.NVarChar,500),
new SqlParameter("@logo",SqlDbType.Image)
};
parms[0].Value = "旅業(yè)互動";
parms[1].Value = "lyhd";
parms[2].Value = "簡介";

string filePath = @"c:\1.jpg";
FileStream fs = File.OpenRead(filePath);

byte[] content = new byte[fs.Length];

fs.Read(content, 0, content.Length);

fs.Close();

parms[3].Value = content;

DBHelper.ExecuteNonQuery(CommandType.Text, strSql, parms);
}

讀取圖片的頁面 test.aspx
復(fù)制代碼 代碼如下:

protected void Page_Load(object sender, EventArgs e)
{
string strSql = "select * from cinfo where id=1";
SqlDataReader reader=DBHelper.ExecuteReader(CommandType.Text, strSql, null);
if(reader.Read())
{
byte[] c=(byte[])reader["logo"];
Response.BinaryWrite(c);
}
}

用來顯示圖片的頁面 test2.aspx
復(fù)制代碼 代碼如下:

<img src="test.aspx" />

相關(guān)文章

最新評論