Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: file image url
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.
Posted 10-Aug-12 19:17pm
Comments
Wes Aday at 11-Aug-12 1:28am
   
And the actual problem that you have is....?
Member 8759797 at 11-Aug-12 11:04am
   
So sorry! I see your dilemma...
 
My problem is that in the ImageUrl field I have "ImgLnk" which is a url field in my database. I can't show the picture because I can't convey to ImageUrl to use the file path "ImgLnk" in database to retrieve the picture. Currently ImageUrl is trying to find the path "ImgLnk" as thought ImgLnk were a Url.
 
I hope this explanation helps you guide me to the correction I need to make as this is the last part of the project and I am stuck! Thanks.
Mohamed Mitwalli at 11-Aug-12 2:37am
   
Hi ,
Make sure of your select statement
string strSelect = "SELECT ImgLnk FROM Business WHERE ImgLnk = @ImgLnk";
in your where condiation you passing Imglnk to get imglnk
Member 8759797 at 11-Aug-12 11:09am
   
Yes thank you for your suggestion. I do feel this is a problem. In my ImgUrl I have "ImgLnk", but I don't know how to tell ImageUrl to use the file path in the database column ImgLnk and not to use ImgLnk as the file path.
 
This process works fine in Gridview when I use DataImageUrlField="ImgLnk". I am hoping to not use Gridview but to show the image directly. Thanks so much for any help you can offer!

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
Member 8759797 at 11-Aug-12 11:15am
   
Thank you for your suggestion. It is helpful and I am sure I can use it. This problem I am having relates to passing a file path stored in a database to the asp:Image option thru the parameter ImageUrl. So the image is not on the database directly but rather the link to the picture. Can you help in this area? I hope so. Thanks for you time!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 CPallini 550
1 Sergey Alexandrovich Kryukov 420
2 George Jonsson 288
3 Pheonyx 218
4 OriginalGriff 200
0 OriginalGriff 4,813
1 CPallini 3,890
2 Sergey Alexandrovich Kryukov 3,274
3 George Jonsson 2,552
4 Gihan Liyanage 2,186


Advertise | Privacy | Mobile
Web04 | 2.8.140905.1 | Last Updated 11 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100