Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear sir;

i have problem to retrieving image from sql.when i click on the search button the text will be displayed in the text field but image is crashed (i want to show image in image box but does not display). please help me as soon as possible.
thanks in advance
for further detail please see my code.
C#
protected void btnselect_Click(object sender, EventArgs e)
        {
            string table_naame = drp_table.SelectedItem.Text.ToString();
            string number = txtno.Text;
            try
            {
                if (con.State == ConnectionState.Closed)
                {
                    con.Open();
                }
                string query = "Select headlines,detail,ImagePath From " + @table_naame + " Where ID=" + @number + "";
                com = new SqlCommand(query, con);
                SqlDataAdapter da = new SqlDataAdapter(com);
                DataTable dt = new DataTable();
                da.Fill(dt);
                txtheaadline.Text = dt.Rows[0]["headlines"].ToString();
                txtdetail.Text = dt.Rows[0]["Detail"].ToString();
                ImageDisplay.ImageUrl = dt.Rows[0]["ImagePath"].ToString();
 }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (con.State == ConnectionState.Open)
                {
                    con.Close();
                }
            }
Posted
Comments
You have to debug and check the url. Then check if the url is correct and the image exists.
Wajid Khaksar 22-Nov-15 12:51pm    
sir i debugged it. The image name with extension exist in url
Suvendu Shekhar Giri 22-Nov-15 12:28pm    
Your code is vulnerable to SQL Injection[^]
Try Parameterized Query[^] or Stored Procedure[^] to avoid this.

1 solution

It appears to me as Image URL issue. Usually the Image URL will be a relative path to the web application. Please take a look at the following posts

http://stackoverflow.com/questions/4665160/image-url-is-correct-but-image-not-showing[^]

http://stackoverflow.com/questions/23693363/how-to-display-image-using-imageurl-in-c-sharp[^]
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900