Retrieve Image from database

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Retrieve Image from database

bryan1709
Hi guys,

I'm posting another thread as i have 2 different problem for my PDF. I have store a binary coded image into the database. This binary coded image has another file(MemberReportImage1) which is there is decode and display the image out. I'm able to display out the image from my webapp. However, whenever i attempt to get the image from the database they will display system.byte() as it is directly retrieve from the database. Hence i'm wondering if there is any way to retrieve the decoded image.

        protected void btnPDF_Click(object sender, EventArgs e)
        {

            var doc1 = new Document();
            var filename = "MyTestPDF" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".pdf";
            var output = new FileStream(Path.Combine("C:\\Users\\apr12mpsip\\Desktop\\New folder", filename), FileMode.Create);
            PdfWriter.GetInstance(doc1, output);
            doc1.Open();

            PdfPTable table = new PdfPTable(2);
            table.TotalWidth = 585f;
            table.LockedWidth = true;

            var logo = iTextSharp.text.Image.GetInstance(Server.MapPath("~/image/logo.jpg"));
            doc1.Add(logo);

            var titleFont = FontFactory.GetFont("Arial", 18, Font.BOLD);
            doc1.Add(new Paragraph("Official Report. Member Report ID : " + DDLCase.SelectedValue, titleFont));


            SqlConnection con = new SqlConnection("Data Source = localhost; Initial Catalog = project; Integrated Security = SSPI");

            SqlCommand cm = new SqlCommand("Select lro.fullname, lro.contact, mr.typeofcrime, mr.location,mr.crdatetime, pr.policeid,  pr.prdatetime, pr.policereport, mr.citizenreport, aor.officialreport from MemberReport mr, PoliceReport pr, LoginRegisterOthers lro, AdminOfficialReport aor where mr.memberreportid = '" + DDLCase.SelectedValue + "' and mr.memberreportid=pr.memberreportid and pr.policereportid=aor.policereportid", con);
            con.Open();
            SqlDataReader dr;

            dr = cm.ExecuteReader();

            if (dr.Read())
            {
               //datareader codes
            }

            dr.Close();
            doc1.Add(table);
            doc1.Close();
            btnPDF.Enabled = false;
        }
    }

Below here is how i retrieve my decode image from my decoding file

if (!DDLCase.SelectedValue.Equals("-1"))
            {
                Session["memberreportid"] = DDLCase.SelectedValue;

                Image1.Attributes["src"] = "MemberReportImage1.aspx?";
                Image1.Attributes["height"] = "300";
                Image1.Attributes["width"] = "300";

                Image2.Attributes["src"] = "MemberReportImage2.aspx?";
                Image2.Attributes["height"] = "300";
                Image2.Attributes["width"] = "300";

                Image3.Attributes["src"] = "MemberReportImage3.aspx?";
                Image3.Attributes["height"] = "300";
                Image3.Attributes["width"] = "300";

                Image4.Attributes["src"] = "MemberReportImage4.aspx?";
                Image4.Attributes["height"] = "300";
                Image4.Attributes["width"] = "300";

                Image5.Attributes["src"] = "MemberReportImage5.aspx?";
                Image5.Attributes["height"] = "300";
                Image5.Attributes["width"] = "300";
            }
Loading...