惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Threat Research - Cisco Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
V
Vulnerabilities – Threatpost
GbyAI
GbyAI
P
Proofpoint News Feed
L
LINUX DO - 热门话题
P
Palo Alto Networks Blog
A
About on SuperTechFans
T
Tenable Blog
M
MIT News - Artificial intelligence
IT之家
IT之家
I
Intezer
D
DataBreaches.Net
爱范儿
爱范儿
T
Threatpost
C
CERT Recently Published Vulnerability Notes
云风的 BLOG
云风的 BLOG
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
K
Kaspersky official blog
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
Y
Y Combinator Blog
Cyberwarzone
Cyberwarzone
酷 壳 – CoolShell
酷 壳 – CoolShell
D
Darknet – Hacking Tools, Hacker News & Cyber Security
H
Help Net Security
Microsoft Security Blog
Microsoft Security Blog
Spread Privacy
Spread Privacy
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
AWS News Blog
AWS News Blog
博客园 - 聂微东
C
Check Point Blog
S
Securelist
有赞技术团队
有赞技术团队
雷峰网
雷峰网
aimingoo的专栏
aimingoo的专栏
Last Week in AI
Last Week in AI
Stack Overflow Blog
Stack Overflow Blog
MongoDB | Blog
MongoDB | Blog
D
Docker
G
GRAHAM CLULEY
T
The Exploit Database - CXSecurity.com
C
Cybersecurity and Infrastructure Security Agency CISA
T
Tailwind CSS Blog
L
Lohrmann on Cybersecurity
G
Google Developers Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LangChain Blog

博客园 - yellowwood

cmder简单使用 回想一下2013中国软件技术大会 Should Assertion Library 数字用千分位表示 从AD( Active Directory )读取 Email 报表产生方式之二比较 报表产生方式之一图示 报表订阅 報表部署 via VS2005 报表参数 報表与子報表 RDL之矩陣 [Oracle整理]数据类型大全 [Oracle整理].NET 调用 Oracle之REF Cursor [Oracle整理]Oracle游标(显示游标&隐式游标&动态游标&参数游标) [Oracle整理]Oracle之Procedure参数类型 [Oracle整理]Oracle之数组 [Oracle整理]Oracle之ROWTYPE和RECORD [Oracle整理]synonym及其应用
报表rdl嵌入网页(ASP.NET)
yellowwood · 2012-02-13 · via 博客园 - yellowwood

1      不含参数

2      含参数

3      常見問題

3.1       報表增加字段rdlc咋辦?

3.2       老是提示:尚未提供資料來源 'titles' 的資料來源執行個體。咋解決?

3.3       提示參數:'pubId' 參數遺漏值

2011127日星期三 上午118

1            不含参数

假定报表已经开发好,报表服务器上的报表为:publishers.rdlTitlesByPublisher.rdl

1 publishers.rdl的扩展名为rdlc,即publishers.rdlc。其它不做任何修改。

2 在已有的专案中,建立一个资料夹,存放报表,例如:Reports

image

3 publishers.rdlc添加到Reports文件夹。

4 新增一个页面用于承载报表(publishers.rdlc),例如:Publishers.aspx

5 reportviewer控件拖到页面Publishers.aspx

image

6 设置reportviewer控件的ProcessingModeLocal,表示在ClientASP.NET)上Run

image

7 写代码为报表赋数据源

1)取得数据源

         public DataSet GetPublishers()

        {

            try

            {

                using (SqlConnection conn = new SqlConnection(connectionString))

                {

                    DataSet ds = new DataSet();

                    string cmdText = "select * from publishers ";

                    SqlCommand comm = new SqlCommand(cmdText, conn);

                    SqlDataAdapter sqlAdapter = new SqlDataAdapter(comm);

                    sqlAdapter.Fill(ds, "publishers");

                    return ds;

                }

            }

            catch (Exception ex)

            {

                throw ex;

            }

        }

2)设置报表参数——路径、数据源

        private void BindReprotData()

        {

            DataSet ds = GetPublishers();

            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)

            {

                this.ReportViewer1.LocalReport.ReportPath = "Reports\\publishers.rdlc";

                this.ReportViewer1.LocalReport.DataSources.Clear();

                this.ReportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WebForms.ReportDataSource("publishers", ds.Tables[0]));

                this.ReportViewer1.DataBind();

            }

        }

8 显示报表

        private string connectionString;

        protected void Page_Load(object sender, EventArgs e)

        {

            connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["pubs"].ConnectionString;

            BindReprotData();

        }

9 结果

image

注意

ReportPath:不可使用“~”。写在代码里,方便使用配置文件。

ProcessingModeLocal

2            含参数

大体思路是:将参数写到SQL里,从DB中获取所需数据,报表参数删掉。

1 publishers.rdl的扩展名为rdlc,即publishers.rdlc。其它不做任何修改。

2 publishers.rdlc添加到項目中。

3 刪除報表中的參數。

image

4 確定,以保存。

5 添加TitlesByPublisher.aspx

6 reportviewer控件拖到页面TitlesByPublisher.aspx

7设置reportviewer控件的ProcessingModeLocal

8 在页面TitlesByPublisher.aspx上,添加一個和文本框和按鈕。ID分別為txtpub_idbtnShow

9 獲取報表數據

1

        private string connectionString;

        protected void Page_Load(object sender, EventArgs e)

        {

            connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["pubs"].ConnectionString;

        }

        public DataSet GetTitlesByPublisher(int pubId)

        {

            try

            {

                using (SqlConnection conn = new SqlConnection(connectionString))

                {

                    DataSet ds = new DataSet();

                    string cmdText = "select * from titles where pub_id=@pubId ";

                    SqlCommand comm = new SqlCommand(cmdText, conn);

                    comm.Parameters.AddWithValue("@pubId", pubId);

                    SqlDataAdapter sqlAdapter = new SqlDataAdapter(comm);

                    sqlAdapter.Fill(ds, "Titles");

                    return ds;

                }

            }

            catch (Exception ex)

            {

                throw ex;

            }

        }

2)設置報表屬性

        private void BindReprotData()

        {

            int pub_id;           

            if (int.TryParse(this.txtpub_id.Text.Trim(), out pub_id))

            {

                DataSet ds = GetTitlesByPublisher(pub_id);

                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)

                {

                    this.ReportViewer1.LocalReport.ReportPath = @"Reports\TitlesByPublisher.rdlc";

                    this.ReportViewer1.LocalReport.DataSources.Clear();

                    this.ReportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WebForms.ReportDataSource("titles", ds.Tables[0]));

                    this.ReportViewer1.DataBind();

                }

            }

        }

10 顯示報表

        protected void btnShow_Click(object sender, EventArgs e)

        {

            BindReprotData();

        }

注意

設報表參數使用Microsoft.Reporting.WebForms.ReportParameter。實踐證明用此性能低。

3            常見問題

3.1  報表增加字段rdlc咋辦?

1 VS工具打開報表項目。

2 修改報表,添加字段。

3 修改擴展名,rdl->rdlc

3.2  老是提示:尚未提供資料來源 'titles' 的資料來源執行個體。咋解決?

1 查看報表的數據源名字。

image

image

2 修改代碼中,數據源的名字。

this.ReportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WebForms.ReportDataSource("titles", ds.Tables[0]))

3.3  提示參數:'pubId' 參數遺漏值

原因:報表參數沒賦值

1 定義報表參數集合

Dim params(1) As Microsoft.Reporting.WebForms.ReportParameter

2 設置每一個參數

Dim p0 As Microsoft.Reporting.WebForms.ReportParameter

'參數的名稱應和RDL報表中的參數名稱一致

p0 = New Microsoft.Reporting.WebForms.ReportParameter("pubId", pubId.Text)

params(0) = p0

3 參數集合添加到報表中

ReportViewer1.LocalReport.SetParameters(params)