|
-
Jul 21st, 2012, 03:09 PM
#1
Thread Starter
Addicted Member
[RESOLVED] RDLC ReportViewer
I have a form with buttons for all my different reports (Report Menu). Each report I made I have been making it's own form with a reportviewer on it. I am wondering if there is a way to have it so when I click the button for the report it uses the same form with reportviewer and just tell it which report to choose attach and rebind the datasource for each specific report?
Thanks for any help! I am very new to vs2010.
Stacy
-
Jul 22nd, 2012, 06:01 PM
#2
Re: RDLC ReportViewer
This is the first answer when I Googled ".Net reportviewer change report" http://www.dreamincode.net/forums/to...-many-reports/
-
Jul 25th, 2012, 10:25 AM
#3
Thread Starter
Addicted Member
Re: RDLC ReportViewer
I have tried using that code but since I am not using a combobox like in the example it doesn't seem to be working properly. What I want to do is have one form with all the buttons for all the different reports and then when the user clicks a button it runs that particular report in the other form with the reportviewer on it. Some of my reports will need input from the user, like a start and stop date. I have all the reports and paramiterized querys finished and they work fine when I use a different reportviewer for each report.
I tried using a splitter and placing the reportviewer on the same form as the buttons with the following code:
ReportViewer1.Reset()
Dim ReportDataSource1 As Microsoft.Reporting.WinForms.ReportDataSource = New Microsoft.Reporting.WinForms.ReportDataSource
ReportDataSource1.Name = "DOTByDateReport_DataTable1"
ReportDataSource1.Value = Me.DOTByDateReport.DataTable1
Me.ReportViewer1.LocalReport.DataSources.Clear()
Me.ReportViewer1.LocalReport.DataSources.Add(ReportDataSource1)
ReportViewer1.LocalReport.ReportEmbeddedResource = "MaintenanceTracker.DOTByDateReport.rdlc"
ReportViewer1.RefreshReport()
But I get an error on the ReportDataSource1.Value = Me.DOTByDateReport.DataTable1 saying DOTByDateReport.DataTable1 is not a member of MaintenanceTracker.Form2.
If I add that dataset to the form, which I thought was the whole point of reusing the reportviewer that I didn't have to add all the datasets for all the different reports, I get the following error: The source of the report definition has not been specified.
This is driving me crazy. Any help would be much appreciated.
P.S. My datasets for all the reports are all different. They are all called <Dataset Name>.Datatable1, but the queries are for different tables and different columns. But I want to be able to have just one reportviewer to view all these reports instead of one for each report.
-
Jul 25th, 2012, 11:42 AM
#4
Re: RDLC ReportViewer
The combobox is just an example and isn't really important, it's the concepts that it demonstrates. As for the datasets, you don't have to add then to the form, you can create them after the operator selects which report to run. Also, if all the reports use data from the same database then the easiest thing would be to create one dataset that contains all the tables, tableadapters and queries (this is what I do). There is no need for different datasets for each report.
-
Jul 25th, 2012, 02:56 PM
#5
Thread Starter
Addicted Member
Re: RDLC ReportViewer
So I can put all the different tables and queries in one dataset and just not add any relation between them? Ok I was making each report their own dataset because most of them use different tables.
Does the code I put above look right because it is not bringing up the report? Do I need to do the Me.DataTable1TableAdapter.Fill(Me.PMDueByEquipReport.DataTable1) at all. That is on the the reportviewer that works for the report right now.
Another thing, on the reportviewer that I want to use with all the reports, do I not attach any tableadapters or reports to it to start with?
Thanks for all your help.
Stacy
-
Jul 25th, 2012, 05:15 PM
#6
Re: RDLC ReportViewer
Never done exactly what you want and haven't used rdlc in a couple of years. Been using Crystal. I would suggest Googling "rdlc dataset runtime" and "vb.net rdlc tutorial"
-
Jul 26th, 2012, 01:10 AM
#7
Re: RDLC ReportViewer
Maybe this will help,
Code:
Dim ds As New WaterTablesDataSet
Dim ta As New WaterTablesDataSetTableAdapters.GroupLotsForUsersTableAdapter
ta.Fill(ds.GroupLotsForUsers)
Me.ReportViewer1.LocalReport.ReportPath = "c:\aquadatatest\aquadatavb2010\report1.rdlc"
Me.ReportViewer1.LocalReport.DataSources.Clear()
Dim sReportDataSource As ReportDataSource
sReportDataSource = New ReportDataSource()
sReportDataSource.Name = "DataSet1"
sReportDataSource.Value = ds.GroupLotsForUsers
ReportViewer1.LocalReport.DataSources.Add(sReportDataSource)
Me.ReportViewer1.RefreshReport()
WaterTablesDataSet is the dataset that I use for all my data access and reporting in my application.
DataSet1 is the name I used when I was initially designing the report and I had set WaterTablesDataset as its datasource.
-
Jul 26th, 2012, 12:30 PM
#8
Thread Starter
Addicted Member
Re: RDLC ReportViewer
THANK YOU! It finally works. I can't thank you enough for all your help I really appreciate it. I think I understand what I was doing wrong too. I was getting screwed up between the dataset and the report dataset.
Have a GREAT day!
Stacy
-
Jul 26th, 2012, 01:11 PM
#9
Thread Starter
Addicted Member
Re: RDLC ReportViewer
Hey one more question have you ever had to have a user input dialogform pop up for one of your reports, i.e. StartDate and StopDate?
I have the Date dialog form done with the following code on the OK button.
Dim ReportViewer As New Form2
Dim zStartDate As String
Dim zStopDate As String
zStartDate = StartDateTextBox.Text
zStopDate = StopDateTextBox.Text
ReportViewer.GetDates(zStartDate, zStopDate)
But then on my form2 when I put your code to run the report I get an error on the
ta.Fill(ds.DataTable1) line because that fill query needs the StartDate and StopDate. So the error says Argument not specified for parameter 'StartDate' of 'Public Overridable Overloads Function Fill(dataTable As PMDueByEquipReport.DataTable1DataTable, StartDate as String, StopDate As String As Integer'.
I have my Dates Dialog Form running before I run the report but it doesn't seem to know that it will get those variables set before it runs the report.
I hope that makes sense. Basically I just need to know how to tell that fill that it will get those parameters. I think I'm missing something.
Thanks for all you help.
Stacy
-
Jul 26th, 2012, 04:06 PM
#10
Re: RDLC ReportViewer
If "ta" requires the dates the why don't you get the dates and then call the fill (ta.fill(ds.dataTable1, zstartdate, zStopDate) ). That's one of the great things about using datasets as a datasource. You casn do all your record filtering with them. You don't need to use report parameters. It gives you a lot more flexibility.
-
Jul 26th, 2012, 04:34 PM
#11
Re: RDLC ReportViewer
Or just add a new tableadapter to the dataset that doesn't have the date arguments. "taNoDateRange.Fill(ds.DataTable1)"
-
Jul 26th, 2012, 05:00 PM
#12
Thread Starter
Addicted Member
Re: RDLC ReportViewer
Guess I am not understanding how to get those values. This is what I have for the button_click to run the report.
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim datesDialog As New StartStopDatesfrm()
Dim StartDate As String
Dim StopDate As String
If datesDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK Then
StartDate = datesDialog.StartDateTextBox.Text
StopDate = datesDialog.StopDateTextBox.Text
Else
End If
datesDialog.Dispose()
Dim ReportViewer As New ReportView
Dim ds As New PMDueByEquipReport
Dim ta As New PMDueByEquipReportTableAdapters.DataTable1TableAdapter
ta.Fill(ds.DataTable1, StartDate, StopDate)
ReportViewer.ReportViewer1.LocalReport.ReportPath = "c:\Users\Stacy\Documents\Visual Studio 2010\Projects\MaintenanceTracker\MaintenanceTracker\PMDueByEquip.rdlc"
ReportViewer.ReportViewer1.LocalReport.DataSources.Clear()
Dim sReportDataSource As ReportDataSource
sReportDataSource = New ReportDataSource()
sReportDataSource.Name = "DataSet1"
sReportDataSource.Value = ds.DataTable1
ReportViewer.ReportViewer1.LocalReport.DataSources.Add(sReportDataSource)
ReportViewer.Show()
ReportViewer.ReportViewer1.RefreshReport()
End Sub
I am running the dates dialog first to get the values but that ta still doesn't think that StartDate and StopDate are going to have a value. If I do the ta.Fill(ds.DataTable1, StartDate, StopDate), StartDate and StopDate are underlined and it says StartDate is used before it has been assigned a value.
I'm definately not understanding something here. Seems like it should work. I click the report button, it opens my dates dialog, user enters dates and clicks ok and it sends those dates to the form that opened it which then runs the report. huh? I'm stumped.
Thanks for sticking in there with me!
Stacy
-
Jul 26th, 2012, 08:30 PM
#13
Re: RDLC ReportViewer
Well, StartDate and StopDate are inside an "if" statement and there is nothing in the "else" section that would assign a value, so it possible for them not to get assigned values. I have no idea for sure what "datesDialog" is returning.
For testing purposes, I would do this,
Code:
Dim StartDate As String = Date.Today.ToShortDateString
Dim StopDate As String = Date.Today.ToShortDateString
If datesDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK Then
StartDate = datesDialog.StartDateTextBox.Text
StopDate = datesDialog.StopDateTextBox.Text
End If
I would put a breakpoint here "ta.Fill(ds.DataTable1, StartDate, StopDate)" and check the date values. This should help you find the problem.
Next time put the codes you post inside the Code brackets, it will make it easier to read.
-
Jul 26th, 2012, 08:49 PM
#14
Thread Starter
Addicted Member
Re: RDLC ReportViewer
The dates dialog is returning the StartDate and StopDate it is the dialog that pops up that allows the user to type in a startdate and stopdate in textboxes. So do I send the dates from the datedialog or get them like the code above on the button click on the parent form?
Totally confused about how to get those dates from the dialog form back to the form that opened the dialog form.
Stacy
-
Jul 26th, 2012, 10:33 PM
#15
Re: RDLC ReportViewer
I don't know anything about retrieving the dates from the datedialog. Did you check the values like l suggested? If the datedialog is not returning what you want, you should post your question in the .Net forum.
-
Jul 26th, 2012, 10:47 PM
#16
Thread Starter
Addicted Member
Re: RDLC ReportViewer
It won't even let me run the program - it has a red x next to the error I typed above.
Thanks.
Stacy
-
Jul 26th, 2012, 10:58 PM
#17
Re: RDLC ReportViewer
Did you change your code like this,
Code:
Dim StartDate As String = Date.Today.ToShortDateString
Dim StopDate As String = Date.Today.ToShortDateString
If datesDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK Then
StartDate = datesDialog.StartDateTextBox.Text
StopDate = datesDialog.StopDateTextBox.Text
End If
-
Jul 26th, 2012, 11:29 PM
#18
Thread Starter
Addicted Member
Re: RDLC ReportViewer
You're my hero! Thank you! That was the problem I had to give the dates a value before I opened my dialog form to let the user input the dates. Works Perfectly!
Stacy
-
Jul 27th, 2012, 12:17 AM
#19
Re: [RESOLVED] RDLC ReportViewer
It's not that they have to have a value before you call the dialog, they must have a value before you call the ta.fill. You had the dates inside an "if" statement and if "datesDialog.ShowDialog(Me)" did not return "OK" then the dates would have no value.
-
Jul 27th, 2012, 12:28 AM
#20
Thread Starter
Addicted Member
Re: [RESOLVED] RDLC ReportViewer
Got it!
Thank you very much.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|