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

1.5k Views Asked by At

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:

enter image description here

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:

enter image description here

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;
2

There are 2 best solutions below

0
ExpertWannaBe On

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.

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
0
khalilsarrar On

do this fun => ReportViewer1.LocalReport.DataSources.Clear(); before not after like that

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