943,945 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 3108
  • ASP.NET RSS
Apr 10th, 2006
0

retieve image from database

Expand Post »
i have stored image in the database.how can i retrieve it a and display in asp.net webform.

am not asking display thru datagrid.i have to put link to those images

plz help me to solve this problem
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vaisakh is offline Offline
11 posts
since Mar 2006
Apr 15th, 2006
0

Re: retieve image from database

I did this a few months ago but here is the code I used.

ASP.NET Syntax (Toggle Plain Text)
  1. private void Page_Load(object sender, System.EventArgs e)
  2. {
  3. dbConn = new System.Data.SqlClient.SqlConnection(ConfigurationSettings.AppSettings["connString"]);
  4. string id = Request.QueryString["id"];
  5.  
  6. string sCmd = "SELECT Photo FROM t_Student_Photos WHERE Photo_Id =" + id;
  7. cmd = new System.Data.SqlClient.SqlCommand(sCmd, dbConn);
  8.  
  9. dbConn.Open();
  10. dbReader = cmd.ExecuteReader();
  11.  
  12. if( dbReader.Read())
  13. {
  14. //Reponse.Content type would have to change depending on the type of image
  15. Response.ContentType = "image\\jpeg";
  16. Response.BinaryWrite((byte[])dbReader["Photo"]);
  17. }
  18.  
  19. //Close Connection
  20. dbConn.Close();
  21. }

And then you would simply put viewimage.aspx?id=1234 as the src in your img tag and it would load the required image from the database.

This probably is not the best or most flexible code buit it does work.

If you have an specific questions just shoot.
Reputation Points: 10
Solved Threads: 1
Light Poster
BlazingWolf is offline Offline
32 posts
since Feb 2006
Apr 16th, 2006
0

Re: retieve image from database

hey u, i have a question.

i want to save colored bold text in database, i didnt suceed in that
the text is inserted empty in the database, i am using html editor

what is the answer?

thanks
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
web_developer is offline Offline
84 posts
since Mar 2006
Apr 16th, 2006
0

Re: retieve image from database

Start your own thread next time...

But put the appropriate HTML tags into the database along with the text.
Reputation Points: 10
Solved Threads: 1
Light Poster
BlazingWolf is offline Offline
32 posts
since Feb 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: can any body help me !!
Next Thread in ASP.NET Forum Timeline: Help Writng and reading cookie





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC