如何在rdlc报告中从数据库导入图像 [英] how to import images from database in rdlc report

查看:59
本文介绍了如何在rdlc报告中从数据库导入图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我的rdlc报告中有一个小问题。所有工作正常的报告都以所需的格式生成,但唯一的是图像没有显示。它们被放置在特定的文件夹中。如何在rdlc报告中显示它们,所有其他数据都显示在数据库中,但只显示图像。请帮助。



Hello everyone, I have a small problem in my rdlc report. All works fine report gets generated in required format, but the only thing is the images are not displaying.They are placed in a particular folder.How to display them in rdlc report, all other data is displayed from database but only images are not displayed.Please help.

dbprocess db = new dbprocess();
   protected void Page_Load(object sender, EventArgs e)
   {
       if (Convert.ToString(Session["usern"]) == "")
           Response.Redirect("login.aspx");
       try
       {
           ReportViewer rpt = new ReportViewer();
           SqlCommand cmd = new SqlCommand();
           SqlConnection conn = new SqlConnection();
           conn = db.openconn();
           cmd.Connection = conn;
           DataSet ds1 = new DataSet();
           //cmd.Parameters.AddWithValue("@tbl", Session["gettable"].ToString());
           //cmd.Parameters.AddWithValue("@instno", Session["usern"].ToString());
           //cmd.Parameters.AddWithValue("@sub_code", Session["sub_code"].ToString());
           //cmd.Parameters.AddWithValue("@c_id", Session["courseid"].ToString());
           //cmd.Parameters.AddWithValue("@col_code", Session["Col_Code"].ToString());

           //cmd.Parameters.AddWithValue("@mode", "report1");
           cmd.Parameters.AddWithValue("@appid", Session["app_id"]);
           if(Convert.ToString(Session["examtype"])=="22222")
               cmd.Parameters.AddWithValue("@mode", "report1");
           else if(Convert.ToString(Session["examtype"])=="11111")
               cmd.Parameters.AddWithValue("@mode", "report2");


           cmd.CommandType = CommandType.StoredProcedure;
           cmd.CommandText = "[RegisterCard_report]";
           SqlDataAdapter da = new SqlDataAdapter(cmd);
           da.Fill(ds1);
           cmd.Parameters.Clear();


           ReportDataSource obj1 = new ReportDataSource("RCBcom_Dataset", ds1.Tables[0]);
           //ReportDataSource obj2 = new ReportDataSource("DataSet2", ds1.Tables[1]);
           //ReportDataSource obj3 = new ReportDataSource("DataSet3", ds1.Tables[2]);


           //string nm = ds1.Tables[2].Rows[0][1].ToString();

           ReportViewer1.LocalReport.DataSources.Add(obj1);
           //ReportViewer1.LocalReport.DataSources.Add(obj2);
           //ReportViewer1.LocalReport.DataSources.Add(obj3);

           if (Convert.ToString(Session["examtype"]) == "22222")
                ReportViewer1.LocalReport.ReportPath = "RCBComreport.rdlc";
           else if (Convert.ToString(Session["examtype"]) == "11111")
               ReportViewer1.LocalReport.ReportPath = "RCBAreport.rdlc";

          // ReportViewer1.LocalReport.ReportPath = "report1.rdlc";
           ReportViewer1.LocalReport.Refresh();
           //-------- Print PDF directly without showing ReportViewer ---
           Warning[] warnings;
           string[] streamids;
           string mimeType;
           string encoding;
           string extension;
           byte[] bytePdfRep = ReportViewer1.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamids, out warnings);
           Response.ClearContent();
           Response.ClearHeaders();
           Response.Buffer = true;
           Response.ContentType = "application/pdf";
           Response.AddHeader("content-disposition", "attachment;filename=\"" + Session["usern"].ToString() + ".pdf" + "\""); //Give file name here
           Response.BinaryWrite(bytePdfRep);
           Session["status"] = 5;
       }
       catch { }

   }

推荐答案

您是将图像存储在数据库中还是仅存储图像路径?



首先,您需要注意一些事情如果从数据库中提取图像,则需要将图像源属性设置为数据库,但如果图像未保存在数据库中,但只有路径,则将其更改为外部。

检查图像的属性。

其次,您能否验证呈现报告中的图像URL是否正确?例如。如果您从报告中复制图像URL - 它是否与实际路径匹配?

只是为了确认您是否复制该URL并粘贴到浏览器地址栏中 - 您确实看到了图像?
Are you storing images in database or just paths to images?

First , you need to take care few things if you are fetching your images from database then you need to set image source property to "Database" but if image is not saved in the database, but only the path to it then changed it to "External".
Check that property of Image.
Second, Can you verify that the image URL in the rendered report is correct? E.g. if you copy image URL from the report - does it match the real path?
Just to confirm if you copy that URL and paste into a browser address bar - you do see the image?


这篇关于如何在rdlc报告中从数据库导入图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆