2013-07-12 5 views
0

보고서 -XmlFile (* .rdlc)에 디자인 타임에 데이터 소스/데이터 집합 정의가 없을 때 프로그래밍 방식으로 데이터 소스/데이터 집합을 Microsoft.Reporting.WebForms.LocalReport에 추가 할 수있는 방법이 있습니까? ? 나는 이미 내 * .rdlcLocalReport에 프로그래밍 방식으로 데이터 소스/데이터 집합 추가

C#

public byte[] RenderReport(string reportName, string reportFormat) 
{ 
    LocalReport report = LoadReport(reportName); 

    //Has same name like DataSet in *.rdlc 
    ReportDataSource rds = new ReportDataSource("DataSet1", getData()); 

    report.DataSources.Clear(); 
    report.DataSources.Add(rds); 

    return report.Render(reportName); 
} 

private DataTable getData() 
{ 
    DataTable dt = new DataTable(); 

    dt.Columns.Add(new DataColumn("ID",typeof(System.String))); 
    dt.Columns.Add(new DataColumn("NAME", typeof(System.String))); 

    dt.Rows.Add(new string[] { "1", "Me" }); 
    return dt; 
} 

* .rdlc

<DataSources> 
    <DataSource Name="DataSource1"> 
     <ConnectionProperties> 
     <DataProvider>System.Data.DataSet</DataProvider> 
     <ConnectString>/* Local Connection */</ConnectString> 
     </ConnectionProperties> 
    </DataSource> 
    </DataSources> 
    <DataSets> 
    <DataSet Name="DataSet1"> 
     <Query> 
     <DataSourceName>DataSource1</DataSourceName> 
     <CommandText>/* Local Query */</CommandText> 
     </Query> 
     <Fields> 
     <Field Name="ID"> 
      <DataField>ID</DataField> 
      <rd:TypeName>System.String</rd:TypeName> 
     </Field> 
     <Field Name="NAME"> 
      <DataField>NAME</DataField> 
      <rd:TypeName>System.String</rd:TypeName> 
     </Field> 
     </Fields> 
    </DataSet> 
    </DataSets> 

에 그러나 경우 데이터 소스/데이터 세트 정의가있는 경우

작동 I 데이터 소스/데이터 집합 정의를 제거합니다.

{Microsoft.Reporting.DefinitionInvalidException : 보고서의 정의가 잘못되었습니다. ---> Microsoft.ReportingServices.ReportProcessing.ReportPublishingException : 'Textbox1'텍스트 상자의 값 식은 'ID'필드를 나타냅니다. 보고서 항목 표현식은 현재 데이터 집합 범위 내의 필드 또는 집계 내에있는 경우 지정된 데이터 집합 범위의 필드를 참조 할 수 있습니다. 필드의 이름의 편지는 올바른 케이스를 사용해야합니다.}

나는 항상 "더미"-datasource/데이터 집합 같은 것을 만들 필요가 마십시오 내 코드에서 무언가를 그리워? 렌더링 프로세스, 아이디어가 나오기 전에 XML을 조작하는 또 다른 솔루션이 있기를 바랍니다.

감사합니다.

답변

0

RDLC를 사용하고 있고 RDLC가 프로젝트에 포함되어있는 경우 RDLC 데이터 집합을 그대로 둘 수 없습니다. 은 어느 쪽이든 당신은 DataSet에 고정 떠나이 항목

// Valid XML with dynamic DataSources and DataSets 
string s = @"<?xml version=""1.0"" encoding=""utf-8""?><Report ...>...</Report>"; 
report.LoadReportDefinition(new MemoryStream(Encoding.UTF8.GetBytes(s))); 
return report.Render(reportName); 
+0

report.Render 매개 변수가 아닌 보고서 이름과 같은 '문자열 형식을'받아들이는 XML에서 보고서 정의를로드하려고 중 유일하게 변경합니다. – narayan

관련 문제