Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
I am using a dynamic table in a dataset and filling it with data from various other tables, based on a linq query. I have created a report.rdlc, based on that table and put it in a reportviewer on the form.

For information, I have used several reports in the ReportViewer control to show pre-filled tables using the TableAdapter.Fill method with success. I only have this problem when I'm using a dynamic table that I fill programmatically.

I have spent an unbelievable amount of hours researching ReportViewer control, Binding Datasets to ReportViewers dynamically, creating datasets, etc.

I have also used the smart tag to choose the proper DataSet and Rebind it, and I still can't get anything to display.

The following is the condensed code which works in a datagridview and also works using Crystal Reports, which I'm trying to get away from:
VB
   Dim ds As New TalkScheduleDataSet
   Dim dt As DataTable = ds.ScheduleReport
   Dim sched = From s In db.TalkSchedules Where s.Date >= CDate(fromDate) And s.Date <= CDate(toDate) Select s

     For Each sch In sched
        'Get the associated data, convert null values, etc.
        dt.Rows.Add(sch.xxxx 'and whatever data needs to inserted )
        dt.AcceptChange
     Next
     'display the report in the datagridview
     'The data shows up in the DataGridview as follows
     dgvReport.DataSource = dt
     dgvReport.Refresh()

     'Set up the report
     ReportViewer.Refresh()
end sub


The data shows in the Datagridview, but the report always shows empty.
I have tried the following:
VB
ReportViewer.LocalReport.DataSources.Add(New Microsoft.Reporting.WinForms.ReportDataSource("TalkScheduleDataSet", dt))
ReportViewer.Update()
ReportViewer.Refresh()


I've tried in various combinations below code:
VB
With ReportViewer
  .ReportPath
  .Reset()
  .LocalReport.DataSources.Add(WinForms.ReportDataSource("DataSetName", dt)
  .Refresh()
End With


Also tried the following after filling the table, which still also shows in DataGrid:
VB
'Also used "ReportSchedule" in place of dt
Dim rds ReportDataSource = new ReportDataSource("TalkScheduleDataSet", dt)
ReportViewer1.LocalReport.DataSources.Clear()
ReportViewer1.LocalReport.DataSources.Add(rds)
ReportViewer1.LocalReport.Refresh();

None of the above shows anything on the reportViewer, and there are no errors.
I've even tried setting up the Table and DataSet using a class, and then referencing it with the ReportViewer.

The ReportViewer works when I use a pre-filled table in a dataset, but I'm confined to only the data from that dataset. I use the dynamic dataset to add data from several tables into one table and display it in the report.

Hope this is clear enough. I know some will think, If it works with CR then why not use CR. The fact is though, I can't get it to work using a ReportViewer, and I don't know why.
Posted
Updated 16-Aug-20 20:26pm

It's been so long that I can't remember ever getting it to work. Out of frustration I went to SAP Crystal Reports and downloaded the Visual Studio Free version.

The new one (I believe It's still free) is here

https://www.sap.com/cmp/td/sap-crystal-reports-visual-studio-trial.html

After installing, you should be able to add a report just like ReportViewer. Again, it's been a while. You may have to experiment with it. There's plenty of online tutorials to get you going. Can't promise anything, but I'll check on some old code I have and see if I can find something.

I believe you can try WPF as well without the hassles. There's a bit of a curve in learning it, but it definitely makes a better looking form when completed.
 
Share this answer
 
as i tried , it must have refreshing in the report. it works for me.

this.reportViewer1.RefreshReport();
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900