【问题标题】:How to add datasource to the local rdlc report dynamically?如何动态地将数据源添加到本地rdlc报告中?
【发布时间】:2013-03-08 06:29:00
【问题描述】:

我是 Windows 桌面应用程序开发的新手。

我有一个包含报表查看器控件的表单。一个包含报告设计的 .rdlc 文件。

我的问题是我想动态绑定报表的数据源。

我的代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;


namespace WindowsFormsApplication3{

    public partial class Form1 : Form{ 

        OleDbConnection cn;
        OleDbCommand cmd;
        OleDbDataAdapter da;
        DataSet ds;

        public Form1(){
            InitializeComponent();
        } 

        private void Form1_Load(object sender, EventArgs e){
            cn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\Bill\\dbBill.accdb");
            string query = "Select * from BillMaster where BillNo=1";
            cn.Open();
            cmd = new OleDbCommand(query, cn);
            da = new OleDbDataAdapter(cmd);
            ds = new DataSet();
            da.Fill(ds);            
            cn.Close();         
        }   
    } 
 }

我想将ds 绑定到我的报告。

报告文件还包含表格和一些显示数据的文本框。

怎么做。?以及如何将数据绑定到.rdlc 文件中的文本框?我搜索了很多,但只找到了 ASP.net 的解决方案。

如何在桌面应用程序中实现这一点。

请帮忙。

提前致谢。

【问题讨论】:

    标签: c# visual-studio-2010 reporting-services desktop-application


    【解决方案1】:

    请看这个article:

    void LocalReport_SubreportProcessing(
        object sender,
        Microsoft.Reporting.WebForms.SubreportProcessingEventArgs e)
    {
        // get empID from the parameters
        int iEmpID = Convert.ToInt32(e.Parameters[0].Values[0]);
    
        // remove all previously attached Datasources, since we want to attach a
        // new one
        e.DataSources.Clear();
    
        // Retrieve employeeFamily list based on EmpID
        var employeeFamily = CpReportCustomData.Data.CustomDS.GetAllEmployeeFamily()
                             .FindAll(element => element.ID == iEmpID);
    
        // add retrieved dataset or you can call it list to data source
        e.DataSources.Add(new Microsoft.Reporting.WebForms.ReportDataSource()
        {
            Name = "DSEmployeeFamily",
            Value = employeeFamily
    
        });
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-13
      • 1970-01-01
      • 1970-01-01
      • 2014-03-30
      • 2012-06-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多