I have table called tbl_studentdetails in which the details of the student are stored when they create a profile.In that form students are supposed to insert a profile picture as well. For that i have created 3 more fields in my table called image_name(short Text) img_size(number), img_data(Ole-Object). The image is saved in the access database but when i try display it on a different page ,it isn't being displayed. There is no error showing and the image data is also fetched from the table properly but it isn't getting displayed on the screen .
Here is code when i save the image in database by converting it into byte array.
protected void btn_create_Click(object sender, EventArgs e)
{
HttpPostedFile postedfile = FileUpload1.PostedFile;
String filename = Path.GetFileName(postedfile.FileName);
String fileextension = Path.GetExtension(filename);
int filesize = postedfile.ContentLength;
if(fileextension.ToLower()==".jpg" || fileextension.ToLower() == ".png")
{
Stream stream = postedfile.InputStream;
BinaryReader binaryReader = new BinaryReader(stream);
byte[] bytes = binaryReader.ReadBytes((int)stream.Length);
con.Open();
OleDbCommand cmd = new OleDbCommand("insert into studentdetails(s_name,age,phone_no,city,state,email,qualification,field,years_exp,description,image_name,img_size,img_data) values('" + txt_name.Text + "'," + txt_age.Text + "," + txt_phone.Text + ",'" + txt_city_stud.Text + "','" + txt_state_stud.Text + "','" + txt_mail.Text + "','" + ddl_qualifiy.SelectedValue + "','" + txt_field.Text + "'," + txt_years.Text + ",'" + txt_extra.Text + "','" + filename + "'," + filesize+",'"+bytes+"')");
cmd.Connection = con;
cmd.ExecuteNonQuery();
Response.Write("<script>alert('Profile created');</script>");
con.Close();
// Session["create_smail"] = txt_mail.Text;
Response.Redirect("~/profilepage.aspx?email=" + txt_mail.Text);
}
and here is the code for when i try to retrieve and display it on the profile page of student on page load
create_email = Request.QueryString["email"];
OleDbCommand cmd = new OleDbCommand("select img_data from studentdetails where email='" + create_email + "'", con);
byte[] bytes = (byte[])cmd.ExecuteScalar();
string strbase64 = Convert.ToBase64String(bytes, 0, bytes.Length);
image1.ImageUrl = "data:image/jpg;base64," + strbase64;
image1 is the id of the asp:image tag where the picture is to be displayed.
Can Someone please help me since i have to submit a project soon.