从数据库中读取多个图像 [英] read more than one image from database
本文介绍了从数据库中读取多个图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将图像保存在数据库中。我使用下面的代码,但它不会返回图像。
if (Request.QueryString [ ProductID]!= null )
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings [ PRODDB跨度>]的ConnectionString)。
string query = SELECT ProductID,ProductName ,ProductImage FROM Product;
SqlDataAdapter da = new SqlDataAdapter(query,con);
DataTable dt = new DataTable();
da.Fill(dt);
for ( int i = 0 ; i < dt.Rows.Count; i ++){
if (dt != null ){
Byte [] bytes =(字节 [])dt.Rows [i] [ ProductImage] ;
Response.Buffer = true ;
Response.Charset = ;
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = Image / png;
Response.AddHeader( content-disposition, attachment; filename =
+ dt.Rows [i] [ ProductName]。ToString());
Response.BinaryWrite(bytes);
Response.Flush();
}
}
Response.Flush();
Response.End();
}
已添加预标签:Amit Kumar [/ Edit]
解决方案
http://www.ezzylearning.com/tutorial。 aspx?tid = 1399196& amp; amp; amp; q = display-images-in-datalist-from-database [ ^ ]
i用过这个。感谢
i am trying to get image saved in the database. i used the code below but it wont return image.
if (Request.QueryString["ProductID"] != null)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ProdDB"].ConnectionString);
string query = "SELECT ProductID, ProductName, ProductImage FROM Product";
SqlDataAdapter da = new SqlDataAdapter(query, con);
DataTable dt = new DataTable();
da.Fill(dt);
for (int i = 0; i < dt.Rows.Count; i++ ){
if (dt != null) {
Byte[] bytes = (Byte[])dt.Rows[i]["ProductImage"];
Response.Buffer = true;
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "Image/png";
Response.AddHeader("content-disposition", "attachment;filename="
+ dt.Rows[i]["ProductName"].ToString());
Response.BinaryWrite(bytes);
Response.Flush();
}
}
Response.Flush();
Response.End ();
}
[Edit]Added Pre Tag : Amit Kumar[/Edit]
解决方案
http://www.ezzylearning.com/tutorial.aspx?tid=1399196&amp;amp;q=display-images-in-datalist-from-database[^]
i used this. thanks
这篇关于从数据库中读取多个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文