从数据库获取url并在文件系统中显示图像 [英] get url from database and display image in file system
本文介绍了从数据库获取url并在文件系统中显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
我正在尝试访问存储在数据库中的url,以使用基于用户选择的asp图像控件显示图像.当用户选择时,我希望显示图像.
url所在的列名称是"ImgLnk"
所以我正在尝试这段代码:
Hello,
I am trying to access a url stored in a database to display an image using asp image control based on user selection. When user selects, I would like image displayed.
The column name where the url is stored is "ImgLnk"
So I am trying this code:
<asp:Image ID="image1" runat="server" ImageUrl="ImgLnk" Height="100px" Width="100px" />
还有我的代码:
And my code behind:
string strConnectionString = ConfigurationManager.ConnectionStrings[""].ConnectionString;
string strSelect = "SELECT ImgLnk FROM Business WHERE ImgLnk = @ImgLnk";
SqlConnection sqlCon = new SqlConnection();
sqlCon.ConnectionString = strConnectionString;
SqlCommand cmdCustomerDetails = new SqlCommand();
cmdCustomerDetails.Connection = sqlCon;
cmdCustomerDetails.CommandType = System.Data.CommandType.Text;
cmdCustomerDetails.CommandText = strSelect;
cmdCustomerDetails.Parameters.AddWithValue("@ImgLnk", strImgLnk);
sqlCon.Open();
//Create DataReader to read the record
SqlDataReader dReader = cmdCustomerDetails.ExecuteReader();
GridView2.DataSource = dReader;
GridView2.DataBind();
while (dReader.Read())
{
image1.ImageUrl = HttpUtility.UrlEncode(dReader["ImgLnk"].ToString());
}
sqlCon.Close();
我不知道还有什么可以尝试的.感谢高手的帮助.
I do not know what else to try. Thanks for help code masters.
推荐答案
请参见以下链接:
http://technico.qnownow.com/display-images -from-database-in-asp-net-gridview-using-httphandler/ [
Hi,
See the below link:
http://technico.qnownow.com/display-images-from-database-in-asp-net-gridview-using-httphandler/[^]
Hope it helps.
这篇关于从数据库获取url并在文件系统中显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文