I'm a bit dumbfounded here. Most of the tutorials I've seen around create a report using the wizard or a built-in (or ready-made) dataset. I build my dataset using queries in runtime so I'm not too sure how to adopt the ones I've seen so far.
Usually, when I create a report, it's a one record report and fields in the RDLC file can easily be populated using parameters. The one I'm trying to do below however works similarly to making a SELECT
query. So here's what I'm trying to do, I'm trying to make a report that shows up like so:
Status: Approved
PID | Name | Address
1 | Name 1 | Address 1
2 | Name 2 | Address 2
===========================
Status: Denied
PID | Name | Address
3 | Name 3 | Address 3
4 | Name 4 | Address 4
I have several questions with this:
My RDLC reports are stored in a "\Reports" folder inside the folder with the .vb/.resx files. When I refer to it's using Application.StartupPath & "\Reports\myReport.rdlc", it can't find it there (obviously). Is there a way for me to embed the report files to the program (ie: use a relative folder name, where should I place the RDLC folder/file)? I don't think I should transfer the RDLC files to the Debug folder just to make this work (hence the full directory listing).
What's a good approach to take in trying to create a report using the code above? I was thinking that if I were to loop along my dataset and pass the values from there to the RDLC file as parameters, it would populate the report (as with my one-record report before) but that doesn't seem to be the case.
Refreshing the report viewer also gives me
A data source instance has not been supplied for the data source 'Dataset1'.
I created a dummy dataset in the RDLC file just to be able to use a Tablix as was suggested in several threads I read around. I'd really prefer if I could just use the dataset I made from scratch rather than use the wizard for that.
Private Sub btnGenerateReport_Click(sender As Object, e As EventArgs) Handles btnGenerateReport.Click Dim query As String query = BuildQuery() SQLControl = New SQLControl Try If Not query = String.Empty Then SQLControl.QueryParams(query) If SQLControl.SQLDS.Tables(0).Rows.Count > 0 Then FetchData() End If End If Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Report Maker") End Try End Sub Private Sub FetchData() Dim dataSource As ReportDataSource Dim PID As Integer Dim Name As String Dim ApplicationStatus As String Dim Address As String rvPreview.Reset() rvPreview.LocalReport.ReportPath = "C:\Users\xxx\Documents\Visual Studio 2015\Projects\My Project 1\My Project 1\Reports\myReport.rdlc" rvPreview.LocalReport.DataSources.Clear() dataSource = New ReportDataSource() _rparams = New List(Of ReportParameter) With SQLControl.SQLDS.Tables(0) For x As Integer = 0 To .Rows.Count - 1 PID = .Rows(x).Item("PID") Name = .Rows(x).Item("LName") & ", " & .Rows(x).Item("FName") ApplicationStatus = .Rows(x).Item("ApplicationStatus") Address = .Rows(x).Item("StreetAddress") & ", " & .Rows(x).Item("City") _rparams.Add(New ReportParameter("PID", PID)) _rparams.Add(New ReportParameter("Name", Name)) _rparams.Add(New ReportParameter("ApplicationStatus", ApplicationStatus)) _rparams.Add(New ReportParameter("Address", Address)) For Each param As ReportParameter In _rparams rvPreview.LocalReport.SetParameters(_rparams) Next Next x rvPreview.RefreshReport() End With End Sub