如何以编程方式将报表与报表查看器绑定 [英] How to bind report with report viewer programmatically

查看:67
本文介绍了如何以编程方式将报表与报表查看器绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



在我的应用程序中,我有一个报表查看器。报表查看器已与一个[ReportVendor]报表绑定。当我点击一个按钮时,我需要将另一个报告[ReportAssetList]与报告查看器绑定。我在下面给出了我的代码。







 私有  void  button1_Click( object  sender,EventArgs e)
{
reportViewer1.Reset();
reportViewer1.ProcessingMode = ProcessingMode.Local;
LocalReport localReport = reportViewer1.LocalReport;
localReport.ReportPath = ReportAssetList.rdlc;
DataSet dataset = new DataSet( DataSetAssetList );

GetAssetDetail( ref 数据集);

// 为销售订单数据创建报表数据源
ReportDataSource datasource = new ReportDataSource();
datasource.Name = assetsBindingSource;
datasource.Value = dataset.Tables [ Assets];
localReport.DataSources.Add(datasource);
reportViewer1.Refresh();
MessageBox.Show( Ok);
}





public void GetAssetDetail( ref DataSet ds)
{
OleDbDataAdapter dataAdapter = new OleDbDataAdapter( SELECT Descriptn,AssetType,Location,Model,SerialNumber,Status,AssetCode,Dateofpurchase, WarrantyExpiry,Condition,Profile FROM Assets,con);
dataAdapter.Fill(ds);
}





请帮帮我..

解决方案

< blockquote>最后我找到了互联网的答案。



 OleDbDataAdapter dataAdapter =  new  OleDbDataAdapter(  SELECT Descriptn,AssetType,Location,Model,SerialNumber,Status,AssetCode,Dateofpurchase,WarrantyExpiry,Condition ,资产来源资产,con); 
DataSet ds = new DataSet();
dataAdapter.Fill(ds);
reportViewer1.Reset();
this .reportViewer1.LocalReport.DataSources.Clear();
ReportDataSource reportDataSource = new ReportDataSource();
reportDataSource.Value = ds.Tables [ 0 ];
reportDataSource.Name = DataSetAssetList;
this .reportViewer1.LocalReport.DataSources.Add(reportDataSource);
this .reportViewer1.LocalReport.ReportEmbeddedResource = AssestsManagementSystem.ReportAssetList.rdlc;
this .reportViewer1.RefreshReport();


Hi Everyone,

In my application I have one report viewer. The report viewer already binded with one [ReportVendor] report. While I'm clicking one button,I need to bind another report[ReportAssetList] with the report viewer. I have given my code below.



private void button1_Click(object sender, EventArgs e)
        {
            reportViewer1.Reset();
            reportViewer1.ProcessingMode = ProcessingMode.Local;
            LocalReport localReport = reportViewer1.LocalReport;
            localReport.ReportPath = "ReportAssetList.rdlc";
            DataSet dataset = new DataSet("DataSetAssetList");

            GetAssetDetail(ref dataset);

            // Create a report data source for the sales order data
            ReportDataSource datasource = new ReportDataSource();
            datasource.Name = "assetsBindingSource";
            datasource.Value = dataset.Tables["Assets"];
            localReport.DataSources.Add(datasource);
            reportViewer1.Refresh();
            MessageBox.Show("Ok");
       }





public void GetAssetDetail(ref DataSet ds)
        {
            OleDbDataAdapter dataAdapter = new OleDbDataAdapter("SELECT Descriptn,                 AssetType, Location, Model, SerialNumber, Status, AssetCode, Dateofpurchase, WarrantyExpiry, Condition, Profile FROM Assets", con);
            dataAdapter.Fill(ds);
        }



Please help me with this..

解决方案

At last I found the answer form Internet.

OleDbDataAdapter dataAdapter = new OleDbDataAdapter("SELECT Descriptn, AssetType, Location, Model, SerialNumber, Status, AssetCode, Dateofpurchase, WarrantyExpiry, Condition, Profile FROM Assets", con);
            DataSet ds = new DataSet();
            dataAdapter.Fill(ds);
            reportViewer1.Reset();
            this.reportViewer1.LocalReport.DataSources.Clear();
            ReportDataSource reportDataSource = new ReportDataSource();
            reportDataSource.Value = ds.Tables[0];
            reportDataSource.Name = "DataSetAssetList";
            this.reportViewer1.LocalReport.DataSources.Add(reportDataSource);            
            this.reportViewer1.LocalReport.ReportEmbeddedResource = "AssestsManagementSystem.ReportAssetList.rdlc";            
            this.reportViewer1.RefreshReport();


这篇关于如何以编程方式将报表与报表查看器绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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