Hello, I'm currently working with a program that using the reportviewer in VS 2012. I have been looking online since yesterday, trying to find any kind of tutorial on how to switch between reports. I have this so far, but it doesn't work. I have another snippet I've been trying to work with, and it too is having issues. This code directly below doesn't throw any errors, the set after it does.

                //i don't use these blocks of code at the same time...
             this.reportViewer1.LocalReport.DataSources.Clear();
                DataTable dt = new DataTable();
                dt = this.DataTable1TableAdapter.GetData();
                string name = "DataSet1"; // this must exist in the RDLC file 
                Microsoft.Reporting.WinForms.ReportDataSource rprtDTSource = new Microsoft.Reporting.WinForms.ReportDataSource(name, dt);

                this.reportViewer1.LocalReport.DataSources.Add(rprtDTSource);
                this.reportViewer1.RefreshReport();


                //2nd set of code i've been trying
                Microsoft.Reporting.WinForms.ReportDataSource rds = new
                Microsoft.Reporting.WinForms.ReportDataSource();
                rds.Name = databaseDataTable.TableName;
                rds.Value = myDataTable;
                reportViewer1.LocalReport.ReportPath = "Report2.rdlc";
                reportViewer1.LocalReport.DataSources.Clear();
                reportViewer1.LocalReport.DataSources.Add(rds);
                reportViewer1.RefreshReport();

Ok, I've changed some code around, it's not working, but the reportviewer doesn't give an error, it just shows as blank(which it shouldn't, i have data in my database and the reports are valid)

                DataSet dataSet2 = new DataSet();
                reportViewer1.Reset();
    reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("dataSet2", "ObjectDataSource2"));
    reportViewer1.LocalReport.ReportPath = @"Report2.rdlc";
    reportViewer1.LocalReport.Refresh(); 

I guess what I see happening here, which I've never worked with this type of object in C# before...is that the ObjectDataSource2 is not being used properly. I'm not even sure what it's named.I'm terrible, I know. I guess my question should be, how do I figure out what my objectdatasource is....? Please don't burn me at the stake.

I think I figured it out. I think that ObjectDataSource is exactly what I'm missing. I have a video that goes over this that I'm watching. If I figure it out, I'll post what I found here. Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.