简体   繁体   English

尚未为数据源rdlc报告提供数据源实例

[英]A data source instance has not been supplied for the data source rdlc report

i am trying to create a parameterized report using two data table in one dataset this is because in the first datatable i am getting all the records and displaying it on the page load event but when the user enters a from date and to date parameter and click filter i would like for the report to change to the other datatable that takes in the parameters. 我试图在一个数据集中使用两个数据表创建一个参数化报告,这是因为在第一个数据表中,我正在获取所有记录并将其显示在页面加载事件中,但是当用户输入起始日期和结束日期参数并单击时过滤器,我希望报表更改为包含参数的其他数据表。

What appreas at page load: 页面加载时会发生什么:

在此处输入图片说明

i accomplished the above with this code 我用这段代码完成了上面的工作

     if (Page.IsPostBack == false)
                {
     NetWeightIolaDataSet.Net_Weight_Tracking1DataTable table = new NetWeightIolaDataSet.Net_Weight_Tracking1DataTable();
                    NetWeightIolaDataSetTableAdapters.Net_Weight_Tracking1TableAdapter adpt = 
new NetWeightIolaDataSetTableAdapters.Net_Weight_Tracking1TableAdapter();
     adpt.Fill(table);
     ReportDataSource rds = new ReportDataSource("NetWeightIolaDataSet_Net_Weight_Tracking1", table);
      ReportViewer1.LocalReport.DataSources.Clear();
      ReportViewer1.LocalReport.DataSources.Add(rds);
      ReportViewer1.LocalReport.Refresh();
      ReportViewer1.Visible = true;
                }

i can get the parameters to work on the report if i use this code and add parameters in the report : 如果我使用此代码并在报告中添加参数,则可以使参数在报告上工作:

//ReportParameter param = new ReportParameter("fromdate", fromdate.Text);
  //this.ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { param });
  //ReportParameter paramm = new ReportParameter("todate", todate.Text);
  //this.ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { paramm });

but i dont want to do it like this instead i would like to pass the parameters to the report via datatable in a dataset and then assign that has a source to the report but when i did that i get this error: 但是我不想这样做,我想通过数据集中的数据表将参数传递给报表,然后将具有源的数据分配给报表,但是当我这样做时,出现此错误:

A data source instance has not been supplied for the data source 'NetWeightIolaDataSet_Net_Weight_Tracking1'.

my dataset: 我的数据集:

在此处输入图片说明

so on page load display all data using datatable with no parameters but when a date range is provided and when the filter button is clicked use the other datatable as the report source: 因此,在页面加载时,将使用不带参数的数据表来显示所有数据,但是当提供日期范围且单击过滤器按钮时,请使用另一个数据表作为报告源:

this is the code for passing the value from the textbox and filling in the datatable with the parameter: 这是用于从文本框中传递值并使用参数填充数据表的代码:

 NetWeightIolaDataSet.Net_Weight_TrackingDataTable table = new NetWeightIolaDataSet.Net_Weight_TrackingDataTable();
            NetWeightIolaDataSetTableAdapters.Net_Weight_TrackingTableAdapter adpt = new NetWeightIolaDataSetTableAdapters.Net_Weight_TrackingTableAdapter();

            adpt.Fill(table, DateTime.Parse(fromdate.Text), DateTime.Parse(todate.Text));
            ReportDataSource rds = new ReportDataSource("NetWeightIolaDataSet_Net_Weight_Tracking", table);
            ReportViewer1.LocalReport.DataSources.Clear();
            ReportViewer1.LocalReport.DataSources.Add(rds);
            ReportViewer1.LocalReport.Refresh();
            ReportViewer1.Visible = true;

So i ended up creating a stored procedure and said that if the parameters are null then give me all records if they have value run the other code and all created a button and called it AllData this will return all records to the user at any point in time. 因此,我最终创建了一个存储过程,并说如果参数为null,则给我所有记录(如果它们具有值)运行其他代码,并创建一个按钮并将其命名为AllData,这将在所有时间将所有记录返回给用户。时间。

Create PROCEDURE [dbo].[filter] 
(
    @mindate DateTime = NULL,
    @maxdate DateTime = NULL

    )
AS
BEGIN
IF ISNULL(@mindate,'')<>'' AND ISNULL(@maxdate,'')<>''
 BEGIN
    SELECT Date, MIN(Date) AS mindate,MAX(Date) AS maxdate, [Unit UPC Base Item], [Item (Optional)], [Preset Number], [Product Group], Shift, [Rotation Code], BBD, [Operator Name], Supervisor, [Production Line], [Bagger Number], [Start Time], [Stop Time], [Under Counts], [Label Wt on Pkg (g)], [Machine Tare Wt (g)], [Actual Tare Wt (g)], [Verify Target Wt (g)], [Total Count (Proper)], [Mean Gross (g)], [Rptd Mean Net (g)], [Std Dev (g)], [Max (g)], [Min (g)], [TNE (g)], Comments, Field1, Field2, Field3
FROM  [Net Weight Tracking]
GROUP BY Date, [Unit UPC Base Item], [Item (Optional)], [Preset Number], [Product Group], Shift, [Rotation Code], BBD, [Operator Name], Supervisor, [Production Line], [Bagger Number], [Start Time], [Stop Time], 
[Under Counts], [Label Wt on Pkg (g)], [Machine Tare Wt (g)], [Actual Tare Wt (g)], [Verify Target Wt (g)], [Total Count (Proper)], [Mean Gross (g)], [Rptd Mean Net (g)], [Std Dev (g)], [Max (g)], [Min (g)], [TNE (g)], 
Comments, Field1, Field2, Field3
HAVING   (MIN(Date) >= @mindate) AND (MAX(Date) <= @maxdate)
END 
ELSE 
BEGIN
SELECT  Date, CONVERT(varchar(10), MIN(Date), 101) AS mindate, CONVERT(varchar(10), MAX(Date), 101) AS maxdate, [Unit UPC Base Item], [Item (Optional)], [Preset Number], [Product Group], Shift, [Rotation Code], BBD, 
 [Operator Name], Supervisor, [Production Line], [Bagger Number], [Start Time], [Stop Time], [Under Counts], [Label Wt on Pkg (g)], [Machine Tare Wt (g)], [Actual Tare Wt (g)], [Verify Target Wt (g)], [Total Count (Proper)], [Mean Gross (g)], [Rptd Mean Net (g)], [Std Dev (g)], [Max (g)], [Min (g)], [TNE (g)], Comments, Field1, Field2, Field3
FROM  [Net Weight Tracking]
GROUP BY Date, [Unit UPC Base Item], [Item (Optional)], [Preset Number], [Product Group], Shift, [Rotation Code], BBD, [Operator Name], Supervisor, [Production Line], [Bagger Number], [Start Time], [Stop Time], 
[Under Counts], [Label Wt on Pkg (g)], [Machine Tare Wt (g)], [Actual Tare Wt (g)], [Verify Target Wt (g)], [Total Count (Proper)], [Mean Gross (g)], [Rptd Mean Net (g)], [Std Dev (g)], [Max (g)], [Min (g)], [TNE (g)], 
 Comments, Field1, Field2, Field3
END
END

do this fun => ReportViewer1.LocalReport.DataSources.Clear(); 做这个有趣=> ReportViewer1.LocalReport.DataSources.Clear(); before not after like that 之前不是那样

ReportViewer1.LocalReport.DataSources.Clear();
ReportDataSource("NetWeightIolaDataSet_Net_Weight_Tracking", table);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM