首页
登录 | 注册

ReportViewer使用


 

 使用ReportViewer出现以下问题:
An error occurred during local report processing.
The definition of the report 'Main Report' is invalid.
An unexpected error occurred in Report Processing.
Could not load file or assembly 'Microsoft.ReportViewer.ProcessingObjectModel, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. 系統找不到指定的檔案。

解决方法:
到微软主页,下载对应的组件安装程序,安装下,即可解决.
http://download.microsoft.com/download/9/8/d/98d5fe84-60ad-4d40-bc25-5f60b9f21a11/ReportViewer.exe
具体使用方法:
先要画好一张报表,报表里的字段要添加一个Dataset,然后在报表里一个一个拖到Table里,设计好的报表是.rdlc文件。
关键代码:
    private void rpt_refresh(string path, string sql, string ds_string)
    {
        if (Session["database"] != null)
        {
            DBClient db = new DBClient(Session["database"].ToString().Trim());
            ReportViewer1.LocalReport.ReportPath = MapPath(path); //设置报表所在路径        
            SqlConnection MyConn=db.createConnection();
            MyConn.Open();
            SqlDataAdapter MyAdapter = new SqlDataAdapter(sql, MyConn);
            DataSet ds = new DataSet();
            MyAdapter.Fill(ds, "aaa");//获得所需要的DATASET
            ReportDataSource rds = new ReportDataSource(ds_string, ds.Tables["aaa"]);//添加报表数据源,和数据表。注意:数据源里的字段必须要在数据表里能找到对应的字段。
            ReportViewer1.LocalReport.DataSources.Clear();
            ReportViewer1.LocalReport.DataSources.Add(rds);//添加数据源
            ReportViewer1.LocalReport.Refresh();//刷新报表
        }
        else
        {
            Response.Redirect("~/Default.aspx");
        }       
    }
本文来源于Woody的鸟窝(Woody's Blog) http://www.smartgz.com, 原文地址:http://www.smartgz.com/blog/Article/920.asp



2020 unjeep.com webmaster#unjeep.com
11 q. 0.010 s.
京ICP备10005923号