2016-09-01 7 views
0

WindowsFormHost 내에 ReportViewer를 만들었습니다. 여기에 내 XAML 코드가 있습니다.데이터 세트의 데이터를 ReportViewer에 표시하려면 어떻게합니까?

<Grid x:Name="grdPrintingGrid" Visibility="Visible" Height="440" Margin="105, 0, 0 0" VerticalAlignment="Top" Grid.ColumnSpan="2" > 
     <TextBox x:Name="txtPRTTitle" IsReadOnly="True" HorizontalAlignment="Left" Height="32" Margin="10,4,0,0" VerticalAlignment="Top" Width="450" FontFamily="Arial" FontSize="18.667" Background="#FFE8F9FF" BorderThickness="0"/> 
     <WindowsFormsHost x:Name="wfhFormsHost" Visibility="Hidden" HorizontalAlignment="Left" Height="312" Margin="10,54,0,0" VerticalAlignment="Top" Width="683"> 
      <rv:ReportViewer x:Name="rvWeeklyList" /> 
     </WindowsFormsHost> 

     <Grid x:Name="grdPWLGrid" Visibility="Visible" Height="440" Margin="0, 0, 0 0" VerticalAlignment="Top"> 
      <DataGrid IsReadOnly="True" Name="dgPWLCGrid" ScrollViewer.HorizontalScrollBarVisibility="Hidden" Background="#FFE8F9FF" HorizontalAlignment="Left" VerticalAlignment="Top" Height="255" Margin="10,62,0,0" Width="693" BorderThickness="1" BorderBrush="Black" CanUserResizeRows="False" > 
      </DataGrid> 

      <Button x:Name="btnPWLPrint" Content="Print" HorizontalAlignment="Left" Height="26" Margin="307,388,0,0" VerticalAlignment="Top" Width="74" FontFamily="Arial" FontSize="14.667" Background="#FFEEFFFF" Click="btnPWLPrint_Click"/> 
     </Grid> 
    </Grid> 

데이터를 가져 오기 위해 데이터베이스에서 저장 프로 시저를 호출합니다. 보고서 마법사를 사용하여 보고서 rdlc를 만듭니다. 나는 그것을 PrintWeeklyList.rdlc라고 불렀다. 데이터 소스 유형 선택 데이터베이스를 선택했습니다. 데이터베이스 모델 선택 데이터 세트를 선택합니다. 데이터베이스 개체의 경우 GetPrintWeeklyListData이라는 저장 프로 시저를 선택합니다. 나는 데이터 소스에 PrintWeeklyListDataSet이라는 이름을 주었다. DataSet에 PrintWeeklyListDS이라는 이름을 지정했습니다.

여기하여의 ReportViewer를로드하는 내 C# 코드입니다 :

private void RVWeeklyList_Load(object sender, EventArgs e) 
{ 
     if (!isReportViewerLoaded) 
     { 
      ReportViewer rvWeeklyList = new ReportViewer(); 

      Microsoft.Reporting.WinForms.ReportDataSource reportDataSource1 = 
       new Microsoft.Reporting.WinForms.ReportDataSource(); 

      PrintWeeklyListDataSet dataset = new PrintWeeklyListDataSet(); 

      dataset.BeginInit(); 

      reportDataSource1.Name = "PrintWeeklyListDS"; //Name of the report dataset in our .RDLC file 
      reportDataSource1.Value = dataset.GetPrintWeeklyListData; 
      rvWeeklyList.LocalReport.DataSources.Add(reportDataSource1); 

      //rvWeeklyList.ServerReport.GetDataSources(); 
      rvWeeklyList.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local; 
      rvWeeklyList.LocalReport.ReportEmbeddedResource = "PrintWeeklyList.rdlc"; 

      dataset.EndInit(); 
      PrintWeeklyListDataSetTableAdapters.GetPrintWeeklyListDataTableAdapter pwlTableAdapter = 
       new PrintWeeklyListDataSetTableAdapters.GetPrintWeeklyListDataTableAdapter(); 
      pwlTableAdapter.ClearBeforeFill = true; 
      pwlTableAdapter.Fill(dataset.GetPrintWeeklyListData); 


      rvWeeklyList.LocalReport.Refresh(); 
      rvWeeklyList.RefreshReport(); 


      isReportViewerLoaded = true; 
     } 
    } 

내가 데이터 세트와 rvWeeklyList 모두 그들에 저장 프로 시저에서 데이터를 볼 코드를 단계별로. 나는 Google을 검색해 왔으며 데이터를 표시하기 위해 내가 누락 된 항목을 파악할 수 없습니다. 모든 코드 예제는 크게 감사하겠습니다.

답변

0

첫째, PrintWeeklyList.rdlc 파일의 Build Action은 이제 아래의 수정 된 코드를 사용하여 비주얼의 이름으로 문자열 <VisualStudioProjectName>을 교체해야 Embedded Resource

로 설정되어 있는지 확인 WindowsFormsHost

Visibility="Visible"에 두 번째 변경 ReportEmbeddedResource에 대한 Studio 프로젝트 :

public MainWindow() 
{ 
    InitializeComponent(); 
    rvWeeklyList.Load += RVWeeklyList_Load; 
} 

private void RVWeeklyList_Load(object sender, EventArgs e) 
{ 
    if (!isReportViewerLoaded) 
    { 
     Microsoft.Reporting.WinForms.ReportDataSource reportDataSource1 = 
      new Microsoft.Reporting.WinForms.ReportDataSource(); 

     PrintWeeklyListDataSet dataset = new PrintWeeklyListDataSet(); 

     dataset.BeginInit(); 

     reportDataSource1.Name = "PrintWeeklyListDS"; 
     reportDataSource1.Value = dataset.GetPrintWeeklyListData; 
     rvWeeklyList.LocalReport.DataSources.Add(reportDataSource1); 

     rvWeeklyList.LocalReport.ReportEmbeddedResource = 
      @"<VisualStudioProjectName>.PrintWeeklyList.rdlc"; 

     dataset.EndInit(); 

     PrintWeeklyListDataSetTableAdapters.GetPrintWeeklyListDataTableAdapter pwlTableAdapter = 
      new PrintWeeklyListDataSetTableAdapters.GetPrintWeeklyListDataTableAdapter(); 
     pwlTableAdapter.ClearBeforeFill = true; 
     pwlTableAdapter.Fill(dataset.GetPrintWeeklyListData); 

     rvWeeklyList.RefreshReport(); 

     isReportViewerLoaded = true; 
    } 
} 

MSDN 문서 참조 : https://msdn.microsoft.com/en-us/library/hh273267.aspx

+0

#sly - 내가 제안한 변경 사항을 적용했습니다. 이제이 오류가 발생합니다. "로컬 보고서 처리 중에 오류가 발생했습니다. 보고서 'PrintWeeklyList'에 대한 보고서 정의가 지정되지 않았습니다. 개체 참조가 개체의 인스턴스로 설정되지 않았습니다." – Cass

+0

@Cass Visual Studio 프로젝트의 이름이 무엇인지 말해 줄 수 있습니까? 나는 ReportEmbeddedResource 문자열이 여전히 잘못되었다고 생각한다. 가능한 경우 내가 무엇이 설정되는지 알려주십시오. – sly

+0

#sly - 죄송합니다. 을 프로젝트 이름으로 바꾸는 것을 잊어 버렸습니다. 일단 그것을 고치면 보고서가 표시됩니다. 고맙습니다! – Cass