Hello,
I would like to know how to:
- Save an image into a Session Variables
- Get the image from the Session Variable and display it on the web page.
Here's the example on how to get the image from the DB:
string v_customer_code = "PAUL";
SqlConnection v_connection = newSqlConnection(ConfigurationManager.ConnectionStrings["SqlServer"].ConnectionString))
v_connection_string = "SELECT [Photo] FROM [customers] WHERE [code] = @CODE";
SqlCommand cmd = new SqlCommand(SQL, v_connection);
cmd.Parameters.AddWithValue("@CODE", v_customer_code);
v_connection.Open();
SqlDataReader dr = cmd.ExecuteReader();
if(dr.Read())
{
Session["Customer_Photo"] = (byte[])dr["Photo"]; ????? is it correct ?????
}
dr.Close();
v_connection.Close();
Loading
Amit ChoudharyPosted Aug 23, 2011, 8:18 AM
But its not preferred to save image in database as bytes cause it can increase your database size proportional to the no. of records + size of image. Also the saving that image to the Session variable can create session problem heavy session mean slow responding app. I suggest you to save image in a directory and store their URL in the Db and fetch the same url associating the information with Customer object and save the customer object in session. But its upto your requirements.
Hope this make sense.