I'm updating an application to .net from VB 6.0. It uses crystal reports to display reports but we get issues around versioning and having to have the client install Crystal so we would prefer not to depend on Crystal.
I was originally going to use an XMLReader object to read in XML generated by a SQL query and a XSLT stylesheet to transform into the reports and I had this working BUT:
- Currently I'm the only one who knows how to generate the XML through a SQL query
- I'm also the only one who really knows how to build a XSLT stylesheet
- It is not exactly easy to produce lovely reports ala Crystal using this method - No WSYWIG
- I don't want to be the only one producing these reports.
- We need some flexability around creating reports
It was suggested to me therefore to look into using the Visual Studio Report Viewer. I can't really find much on this apart from examples that use the built in wizards etc. But with the application we are discussing, we want it so that people here can design the reports with the reportViewer in VS but that when the application runs we can change the datasource to point to the applications connection and tables. i.e. I want to be able to load the data I want into the reports on the fly instead of using hardcoded data sources.
Here is what I have so far but although I get no Errors, I also get no report in the viewer. I have made the report RDLC file using the wizard:
Sub ShowReport() dim conn as new SqlConnection (MyConnection) dim cmd as new SqlCommand dim DS as new Dataset dim DT as Datatable dim DA as new SqlDataAdapter Try conn.open with cmd .Connection = conn .CommandType = commandType.StoredProcedure .CommandText = "spGetTransactionsForCreditReport" end with DA.SelectCommand = cmd DA.Fill(DS) DT = DS.Tables(0) Dim RDS As New Microsoft,.Reporting.WinForms.ReportDataSource() 'In my Report2.rdlc file I set it up to use a dataset called transactions RDS.Name = "Transactions" RDS.Value = DT ReportViewer1.LocalReport.DataSources.Add(RDS) ReportViewer1.LocalReport.ReportPath = "Report2.rdlc" ReportViewer1.LocalReport.ReportEmbeddedSource = "Report2.rdlc" ReportViewer1.LocalReport.Refresh() Catch ex as Exception MsgBox(ex.Message, MsgBoxStyle.Critical, "An Error Occurred") Finally If conn.State <> ConnectionState.Closed then conn.close conn.dispose end if End Try End Sub
I just get a blank reportviewer... Anyone done something like this before? I cannot believe there is no way to populate these on the fly.