How to display image on webform (image control)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • IssueNotTissue
    New Member
    • Jan 2013
    • 7

    How to display image on webform (image control)

    My image is being stored in a folder called D:\Project\Imag e\...jpg
    Inside my Mircosoft access i made a field called ImageFile . And copy paste the image path into the field in text

    Using
    Code:
    OleDbCommand sqlquery = new OleDbCommand("SELECT * FROM StudentDatabase WHERE Name ='" + TxtName.Text + "' ", ConnectionString);
     OleDbDataReader reader = sqlquery.ExecuteReader();
     while (reader.Read())
    {
    Image2.ImageUrl += reader[9] + "";
    }
    Here is my code -- which is not giving me anything
    ps i am a beginner

    How do i make the image appear at the Image Control Image2

    How do i convert text into image?
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Why return all the fields in that query when all you need is the image path field? Are you sure the image path field is the tenth field in the recordset? You should check the value is actually returning what you think it's returning. You should be aware that field numbering starts at 0. Also, does it work if you hard code the path? These are some basic troubleshooting steps you should take first.

    Comment

    • IssueNotTissue
      New Member
      • Jan 2013
      • 7

      #3
      Because i doing a Personal Particular Update form with all the other details.

      Reader[9] will show the image path

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        How do you know that reader[9] will show the image path? Did you try the hard coding troubleshooting step?

        Comment

        • IssueNotTissue
          New Member
          • Jan 2013
          • 7

          #5
          i used the watch function when i debug and the path came out

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            Why do you keep ignoring my question about the hard coding test?

            What is the path that it shows?

            Comment

            • IssueNotTissue
              New Member
              • Jan 2013
              • 7

              #7
              reader[9] | "\\Images\\1111 11A.jpg" object {string}

              Comment

              • Rabbit
                Recognized Expert MVP
                • Jan 2007
                • 12517

                #8
                I don't know why this is the fourth time I've had to ask this. Why do you keep ignoring my question about the hard coding test?

                Comment

                • IssueNotTissue
                  New Member
                  • Jan 2013
                  • 7

                  #9
                  sorry rabbit i dont think i get what u mean

                  Sorry if i am troubling but i think i really need your help.

                  D:\Apple\Images \101010A.gif << is where my picture is located.

                  How do i rephase it and type it into microsoft access so that when i use

                  Image2.ImageUrl = reader[9].ToString();

                  the image will appear?

                  Comment

                  • Frinavale
                    Recognized Expert Expert
                    • Oct 2006
                    • 9749

                    #10
                    @IssueNotTissue ,

                    There could be a number of reasons why this is not working for you.
                    • As @Rabbit suggested, reader[9] may not hold the information you are looking for
                    • The image may not be accessible to the browser where the image resides (the folder may not be accessible from the web)
                    • The URL (path) to the image is incorrect
                    • Your data is stored incorrectly



                    I am going to guess that the image URL is incorrect because you are storing the images in a location that is not accessible from the web. I am making that guess based on your response in post #7, you said that the path is:
                    \\Images\\11111 1A.jpg

                    This is not a valid URL that the web browser understands.

                    It should be:
                    • If the image resides in a folder called Images within the root of where the page is being executed from, your URL should be one of these:
                      • /Images/111111A.jpg
                      • http://localhost/Images/111111A.jpg
                    • If your image resides in a folder called Images located one level up from the page that it is being used in your URL (path) could be:
                      • ../Images/111111A.jpg
                      • http://localhost/Images/111111A.jpg


                    If your images are located somewhere outside of the folder that contains your web application, then you probably cannot access it from the web browser because you cannot form a valid URL to the image.

                    -Frinny

                    Comment

                    • IssueNotTissue
                      New Member
                      • Jan 2013
                      • 7

                      #11
                      D:\Apple\Images \111111A.gif

                      i have enter in the microsoft access field a couple of path using trial & error.

                      using /Images/111111A.jpg i get Local/images/111111A.jpg
                      but using Images/111111A.jpg i get Http://Localhost/Project/Images/111111A.jpg

                      what should i type in the microsoft access

                      Comment

                      • Frinavale
                        Recognized Expert Expert
                        • Oct 2006
                        • 9749

                        #12
                        A web browser does not understand a file path like D:\Apple\Images \111111A.gif. It only understands URLs that it can resolve to retrieve resources (like your pictures).

                        If your web browser cannot retrieve the image, then it cannot display the image. Therefore, you have to make the images available.

                        You need to create a folder called Images in your project and move the images there.

                        You should only need to store the image names in the database...you can then provide the correct URL to the Image control using it.

                        -Frinny
                        Last edited by Frinavale; Jan 22 '13, 02:11 PM.

                        Comment

                        • IssueNotTissue
                          New Member
                          • Jan 2013
                          • 7

                          #13
                          Thanks i solve it :D

                          Comment

                          Working...