简体   繁体   中英

Adding multiple dataset from codebehind to .rdlc report

I have a report in VS2008 with a table and 10 text boxes.I have bound values to table from DB-table sucesfully.But how to bind the text boxes with a different DB-table in the same report? How to bind multiple data sets in same code-behind at a time ? what if am using more than one query to get data for a single report? sample code i did is below here- its to bind data to table in the .rdlc.`

// A table mapping names the DataTable.

            adapter.TableMappings.Add("View", mappingTableDataSet);

            // Open the connection.
            connection.Open();
            Console.WriteLine("\nThe SqlConnection is open.");

            SqlCommand command = new SqlCommand(queryString, connection);
            command.CommandType = CommandType.Text;

            // Set the SqlDataAdapter's SelectCommand.
            adapter.SelectCommand = command;
            command.ExecuteNonQuery();

            // Fill the DataSet.
            DataSet dataset = new DataSet(mappingTableDataSet);
            adapter.Fill(dataset);

            //Set up reportviewver and specify path
            ReportViewer viewer = new ReportViewer();
            viewer.ProcessingMode = ProcessingMode.Local;
            viewer.LocalReport.ReportPath = reportPath;

            //specify the dataset syntax = (datasetofreport.rdlc,querydataset); 
            viewer.LocalReport.DataSources.Add(new ReportDataSource(reportDataSource, dataset.Tables[0]));
            //viewer.LocalReport.DataSources.Add(new ReportDataSource("podDataSet_Route_Summary", dataset.Tables[0]));
            connection.Close();`

I tried the following and it worked.Here each 'dataset' from query result should be mapped with corresponding 'reportDataSource' otherwise it will through error saying 'reportDataSource' not available.We need to provide as much datasets as we use reportdatasources respectively as follows

                viewer.LocalReport.DataSources.Add(new ReportDataSource(reportDataSource, dataset.Tables[0]));
                viewer.LocalReport.DataSources.Add(new ReportDataSource("reportDataSource1", dataset.Tables[1]));
                viewer.LocalReport.DataSources.Add(new ReportDataSource("reportDataSource2", dataset.Tables[2]));
                viewer.LocalReport.DataSources.Add(new ReportDataSource("reportDataSource3", dataset.Tables[3]));
                viewer.LocalReport.DataSources.Add(new ReportDataSource("reportDataSource4", dataset.Tables[4]));

Here each 'reportDataSource' corresponds to diffrent part of single report.Eg:Table,Textbox,Matrix which are independently kept in single report

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM