報表的使用

來源:互聯網
上載者:User
使用RDLC報表(二)--使用自訂資料集2007-10-26 17:27
<!--[if !supportLists]-->1<!--[endif]-->建立表單

<!--[if !supportLists]-->2<!--[endif]-->建立資料來源

3<!--[endif]-->建立報表

新的資料報表已經產生,下面開始對資料來源進行設定。

<!--[if !supportLists]-->4<!--[endif]-->對報表自動產生的資料來源進行設定

選擇工具列 à 報表 à 資料來源,選中所要修改的資料來源後,用“重新命名”對其進行修改,如myds。

 

修改完成後,確定退出此視窗。

 

選中報表設計師內的表格,顯示內容。將表格的資料集名稱更改為上面修改的名稱。

如果一個報表檔案內只有一個資料來源,則表格內的資料值可直接寫為“=Fields!欄位.Value”的格式,如果包含多個資料來源,則要對此欄位的取值進行指定,如“=(Fields!欄位.value,“資料集名稱””。

<!--[if !supportLists]-->5<!--[endif]-->手動產生資料來源

手動產生的資料集內必須包含報表檔案內設計的欄位名稱,否則會運行出現錯誤。

產生資料集:

 

       /// <summary>

        /// 報表執行操作

        /// </summary>

        /// <param name="sender"></param>

        /// <param name="e"></param>

        private void button1_Click(object sender, EventArgs e)

         {

            //取得資料集

            string connstring = "Data Source=.;Initial Catalog=Northwind;Integrated Security=True";

             System.Data.SqlClient.SqlConnection conn1 = new System.Data.SqlClient.SqlConnection(connstring);

             System.Data.SqlClient.SqlCommand command1 = new System.Data.SqlClient.SqlCommand("select * from customers", conn1);

             System.Data.SqlClient.SqlDataAdapter ada1 = new System.Data.SqlClient.SqlDataAdapter(command1);

             DataSet c_ds = new DataSet();

            try

             {

                 conn1.Open();

                 ada1.Fill(c_ds);

             }

            finally

             {

                 conn1.Close();

                 command1.Dispose();

                 conn1.Dispose();

             }

            //為報表瀏覽器指定報表檔案

            this.reportViewer1.LocalReport.ReportEmbeddedResource = "report.Report1.rdlc";

            //指定資料集,資料集名稱後為表,不是DataSet類型的資料集

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

            this.reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("myds", c_ds.Tables[0]));

            //顯示報表

            this.reportViewer1.RefreshReport();

         }

 

運行後的資料顯示:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.