0

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

3
Contributors
3
Replies
4
Views
10 Years
Discussion Span
Last Post by BlazingWolf
0

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

private void Page_Load(object sender, System.EventArgs e)
{
	dbConn = new System.Data.SqlClient.SqlConnection(ConfigurationSettings.AppSettings["connString"]);
	string id = Request.QueryString["id"];
			
	string sCmd = "SELECT Photo FROM t_Student_Photos  WHERE Photo_Id =" + id;
	cmd = new System.Data.SqlClient.SqlCommand(sCmd, dbConn);

	dbConn.Open();
	dbReader = cmd.ExecuteReader();

	if( dbReader.Read())
		{
                 //Reponse.Content type would have to change depending on the type of image
		Response.ContentType = "image\\jpeg";
		Response.BinaryWrite((byte[])dbReader["Photo"]);
		}

	//Close Connection
	dbConn.Close();
}

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.

0

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

0

Start your own thread next time...

But put the appropriate HTML tags into the database along with the text.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.