2013-11-04 107 views
0

我在VS2008中有一个带有一个表格和10个文本框的报告。我从DB-table中有很多绑定值,但是如何将文本框与不同的DB-表在同一报告中?如何在同一代码背后绑定多个数据集?如果我使用多个查询来获取单个报表的数据,该怎么办?我所做的示例代码如下所示 - 它将数据绑定到.rdlc中的表格。将代码隐藏的多个数据集添加到.rdlc报告

//一个表映射命名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();` 

回答

1

我尝试以下,并worked.Here从查询结果中的每个“数据集”应与相应的“reportDataSource”被映射,否则它会通过错误说“reportDataSource”不available.We需要提供尽可能多的数据集因为我们使用分别reportdatasources如下

   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])); 

这里每个“reportDataSource”对应于单个report.Eg:Table,Textbox,Matrix的不同势部分被单独保持在单一报告