I performed the following code to retrieve the path from database and show image

protected void Button2_Click(object sender, EventArgs e)
    {
        
            string t = TextBox2.Text.Trim();
            SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=D:\\Anshul\\College site\\App_Data\\afset.mdf;Integrated Security=True;User Instance=True");
            SqlCommand cmd = new SqlCommand("Select dmc from Semr Where Rollno='" + t + "'", con);
            con.Open();
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                string p = dr["dmc"].ToString();
                Image2.ImageUrl = p;
            }
        con.Close();
        Image2.Visible = true;
        
    }

but the image is not displayed not even the control. Please help me 1 thing i am sure it retrieves the path.

Recommended Answers

All 4 Replies

i think u might be storing absolute path of image in your database
otherwise it should work..!

on debug wot is the image path did u get ... post it

D:\\Anshul\\CollegeSite\\Semr\\Photo.jpg
this is the path i get

D:\\Anshul\\CollegeSite\\Semr\\Photo.jpg
this is the path i get

I guess you can only set the relative path in ImageUrl property. not absolute path.

not gonna happen bro..

instead create a directory in your App

and store your images there...

in database assign that path for imageurl

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.