Sasi, if you are still there, I wonder if you'd be willing to help me a bit further. I'm not getting errors anymore with the parameters, but I still can't get the report to render. I'm having trouble with datasources.
My report (SalesReport.rdlc) has two string parameters, Quarter and AgencyType. Here's the code I'm using (I'm not using the Source Code tool in this editor as it keeps resulting in errors):
With ReportViewer1
.Visible = True
.Reset()
.LocalReport.ReportPath = "SalesReport.rdlc"
Dim rdsReport As New ReportDataSource
With rdsReport
.Name = "SalesReport"
.Value = dtReport 'Created earlier in the code
End With
.LocalReport.DataSources.Clear()
.LocalReport.DataSources.Add(rdsReport)
'All RptParam_ variables have been set earlier in the code
Dim prmQrTitle As New ReportParameter("Quarter", RptParam_Qarter)
Dim prmAgencyType As New ReportParameter("AgencyType", RptParam_AgencyType)
Dim parameters() As ReportParameter = {prmQuarter, prmAgencyType}
.LocalReport.SetParameters(parameters)
.DataBind()
.LocalReport.Refresh()
End With
Here are the problems I am experiencing:
If I use the SmartTag of the ReportViewer to create a dataset, it ends up creating a TableAdapter and an ObjectDataSource. I then assign the resulting DataTable to the DataSetName property of the table in the report. When I run this, it goes through the code without an error, but where the report should be rendered (where the ReportViewer is), I get this error:
A data source instance has not been supplied for the data source 'SalesReport_SalesReportTable'
If I reset (delete the value of) the DataSetName property, I get the same error. If I then open the rdlc in a text error and delete the <DataSets> element and all its contents, I get this error at complile:
Error 1 The table ‘table2’ is in the report body but the report has no data set. Data regions are not allowed in reports without datasets.
So, I'm very confused. If I am going to assign a DataTable dynamically (at runtime), do I still need to have the DataSetName property of the report table assigned to a datatable? I think I do, since how would the report know about the fields otherwise at design? But how can I get away from this situation in which I get errors if I assign a DataTable and I get errors if I don't. How DO I set things up so that I can assign a report to a ReportViewer and a DataTable to the LocalReport in code?
Thank you very much for your help.