retieve image from database

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2006
Posts: 11
Reputation: vaisakh is an unknown quantity at this point 
Solved Threads: 0
vaisakh vaisakh is offline Offline
Newbie Poster

retieve image from database

 
0
  #1
Apr 10th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 32
Reputation: BlazingWolf is an unknown quantity at this point 
Solved Threads: 1
BlazingWolf BlazingWolf is offline Offline
Light Poster

Re: retieve image from database

 
0
  #2
Apr 15th, 2006
I did this a few months ago but here is the code I used.

  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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 84
Reputation: web_developer is an unknown quantity at this point 
Solved Threads: 1
web_developer web_developer is offline Offline
Junior Poster in Training

Re: retieve image from database

 
0
  #3
Apr 16th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 32
Reputation: BlazingWolf is an unknown quantity at this point 
Solved Threads: 1
BlazingWolf BlazingWolf is offline Offline
Light Poster

Re: retieve image from database

 
0
  #4
Apr 16th, 2006
Start your own thread next time...

But put the appropriate HTML tags into the database along with the text.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC