RDLC 传参 报表出现错误 (未解决)

经过测试  可以用的 带传参的  RDLC  在vs2019上 能正常运行

但在vs2019上剪切后,保存, 运行就会报An error 错误, ctr+z 全部 撤销后 保存     一样会报  这个错误, 一脸懵逼 ,这是什么鬼!!!  

 

 

public Dictionary<string, Type> Getdt_columns_attribute(DataTable dt)
        {
            if (dt == null) { return null; }
            Dictionary<string, Type> dic = new Dictionary<string, Type>();

            foreach (DataColumn dc in dt.Columns)
            {
                dic.Add(dc.ColumnName, dc.DataType);
            }
            return dic;
        }
        public string get_数据集中字段(Dictionary<string, Type> types)
        {
            /*
            <Fields>
               <Field Name="产品型号">   <!--显示名称-->
                  <DataField>产品型号</DataField>  <!--绑定的数据名称-->
                  <rd:TypeName>System.String</rd:TypeName> <!--绑定的数据类型-->
               </Field>
            </Fields>
             */
            StringBuilder sb = new StringBuilder();
            sb.Append("<Fields>");
            foreach (KeyValuePair<string, Type> kvp in types)
            {
                var t1 = kvp.Key;
                var t2 = kvp.Value.FullName;
                sb.AppendFormat("<Field Name=\"{0}\">", t1);
                sb.AppendFormat("<DataField>{0}</DataField>", t1);
                sb.AppendFormat("<rd:TypeName>{0}</rd:TypeName>", t2);
                sb.AppendFormat("</Field>");

            }
            sb.AppendFormat("</Fields>");

            var t = sb.ToString();
            return sb.ToString();
        }

        public string get_表阵列集合(DataTable dt)
        {
            /*
                 <!--表阵 列集合-->
                    <TablixColumns>
                        <TablixColumn>
                            <Width>1.44804in</Width>
                        </TablixColumn>
                    </TablixColumns>
             */
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("<TablixColumns>");

            foreach (DataColumn dc in dt.Columns)
            {
                sb.AppendFormat("<TablixColumn>");
                sb.AppendFormat("<Width>1.44804in</Width>");
                sb.AppendFormat("</TablixColumn>");
            }
            sb.AppendFormat("</TablixColumns>");

            var t = sb.ToString();
            return sb.ToString();
        }
        public string get_表阵单元格集合(DataTable dt)
        {
            /*
                 <!--表阵单元格集合-->
                            <TablixCells>
                                <TablixCell>
                                    <CellContents><Textbox Name="Textbox1">
                                            <CanGrow>true</CanGrow><KeepTogether>true</KeepTogether><Paragraphs><Paragraph><TextRuns><TextRun>
                                            <Value>产品型号</Value>
                                            <Style><FontFamily>宋体</FontFamily></Style></TextRun></TextRuns><Style><TextAlign>Center</TextAlign></Style></Paragraph></Paragraphs>
                                            <rd:DefaultName>Textbox1</rd:DefaultName>
                                            <Style><Border><Style>Solid<Style></Border><VerticalAlign>Middle</VerticalAlign><PaddingLeft>2pt</PaddingLeft><PaddingRight>2pt</PaddingRight></Style>
                                    </TextBox></CellContents>
                                </TablixCell></TablixCells>
             
             */
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("<TablixCells>");
            for (int i = 0; i < dt.Columns.Count; i++)
            {
                sb.AppendFormat("<TablixCell>");
                sb.AppendFormat("<CellContents><Textbox Name=\"Textbox{0}\">", i);
                sb.AppendFormat("<CanGrow>true</CanGrow><KeepTogether>true</KeepTogether><Paragraphs><Paragraph><TextRuns><TextRun>");
                sb.AppendFormat("<Value>{0}</Value>", dt.Columns[i].ColumnName);
                sb.AppendFormat("<Style><FontFamily>宋体</FontFamily></Style></TextRun></TextRuns><Style><TextAlign>Center</TextAlign></Style></Paragraph></Paragraphs>");
                sb.AppendFormat("<rd:DefaultName>Textbox{0}</rd:DefaultName>", i);
                sb.AppendFormat("<Style><Border><Style>Solid</Style></Border><VerticalAlign>Middle</VerticalAlign><PaddingLeft>2pt</PaddingLeft><PaddingRight>2pt</PaddingRight></Style>");
                sb.AppendFormat("</Textbox></CellContents>");
                sb.AppendFormat("</TablixCell>");
            }
            sb.AppendFormat("</TablixCells>");

            var t = sb.ToString();
            return sb.ToString();

        }
        public string get_表阵单元格集合_赋值(DataTable dt)
        {
            /*
 <TablixCells>
   <TablixCell>

          <CellContents><TextBox Name="产品型号">
       <CanGrow>true</CanGrow> <KeepTogether>true</KeepTogether><Paragraphs><Paragraph><TextRuns><TextRun>
       <Value>=Fields!产品型号.Value</Value>
       <Style><FontFamily>宋体</FontFamily></Style></TextRun></TextRuns><Style><TextAlign>Center</TextAlign></Style></Paragraph></Paragraphs>
       <rd:DefaultName>产品型号</rd:DefaultName>
       <Style><Border><Style>Solid<Style></Border><VerticalAlign>Middle</VerticalAlign><PaddingLeft>2pt</PaddingLeft><PaddingRight>2pt</PaddingRight></Style>
        </TextBox></CellContents>
   </TablixCell>
</TablixCells>
             */

            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("<TablixCells>");
            for (int i = 0; i < dt.Columns.Count; i++)
            {
                sb.AppendFormat("<TablixCell>");
                sb.AppendFormat("<CellContents><Textbox Name=\"{0}\">", dt.Columns[i].ColumnName);
                sb.AppendFormat("<CanGrow>true</CanGrow><KeepTogether>true</KeepTogether><Paragraphs><Paragraph><TextRuns><TextRun>");
                sb.AppendFormat("<Value>=Fields!{0}.Value</Value>", dt.Columns[i].ColumnName);
                sb.AppendFormat("<Style><FontFamily>宋体</FontFamily></Style></TextRun></TextRuns><Style><TextAlign>Center</TextAlign></Style></Paragraph></Paragraphs>");
                sb.AppendFormat("<rd:DefaultName>Textbox{0}</rd:DefaultName>", i);
                sb.AppendFormat("<Style><Border><Style>Solid</Style></Border><VerticalAlign>Middle</VerticalAlign><PaddingLeft>2pt</PaddingLeft><PaddingRight>2pt</PaddingRight></Style>");
                sb.AppendFormat("</Textbox></CellContents>");
                sb.AppendFormat("</TablixCell>");
            }
            sb.AppendFormat("</TablixCells>");

            var t = sb.ToString();
            return sb.ToString();

        }
        public string get_表阵列成员(DataTable dt)
        {
            /*
                       <!--表阵 列成员-->
                    <TablixMembers>
                        <TablixMember />
                    </TablixMembers>
             */
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("<TablixMembers>");
            for (int i = 0; i < dt.Columns.Count; i++)
            {
                sb.AppendFormat("<TablixMember />");
            }
            sb.AppendFormat("</TablixMembers>");

            var t = sb.ToString();
            return sb.ToString();


        }
        //调用
                            var types = Getdt_columns_attribute(dt);
                    get_数据集中字段(types);
                    get_表阵列集合(dt);
                    get_表阵单元格集合(dt);
                    get_表阵单元格集合_赋值(dt);
                    get_表阵列成员(dt);

XML 结构

 

<?xml version="1.0" encoding="utf-8"?>
<Report xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" xmlns="http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition">

<!--数据源-->
  <DataSources>
    <DataSource Name="yderpDataSet">   <!--yderpDataSet为数据集-->
      <ConnectionProperties>
        <DataProvider>System.Data.DataSet</DataProvider>
        <ConnectString>/* Local Connection */</ConnectString>
      </ConnectionProperties>
    </DataSource>
  </DataSources>
<!--数据集-->
  <DataSets>
    <DataSet Name="车间日报表"> <!--表名称-->
    <!--字段-->
    <Fields>
       <Field Name="产品型号">   <!--显示名称-->
          <DataField>产品型号</DataField>  <!--绑定的数据名称-->
          <rd:TypeName>System.String</rd:TypeName> <!--绑定的数据类型-->
       </Field>
    </Fields>
    </DataSet>
  </DataSet>
    <!--主题-->
    <body>
        <ReportItems>
            <!--表阵-->
            <Tablix Name="Tablix1">
                <!--表阵主体-->
                <TablixBody>
                    <!--表阵 列集合-->
                    <TablixColumns>
                        <TablixColumn>
                            <Width>1.44804in</Width>
                        </TablixColumn>
                    </TablixColumns>

                    <!--表阵行集合-->
                    <TabLixRows>
                        <TablixRow>
                            <Height>0.24664in</Height>
                            <!--表阵单元格集合-->
                            <TablixCells>
                                <TablixCell>
                                    <!--单元格内容-->
                                    <CellContents>
                                        <!--文本框-->
                                        <TextBox Name="Textbox1">
                                            <!--可增长-->
                                            <CanGrow>true</CanGrow>
                                            <!--保持一致-->
                                            <KeepTogether>true</KeepTogether>
                                            <!--段落-->
                                            <Paragraphs>
                                                <Paragraph>
                                                    <TextRuns>
                                                        <TextRun>
                                                            <Value>产品型号</Value>
                                                            <!--样式-->
                                                            <Style>
                                                                <FontFamily>宋体</FontFamily>
                                                            </Style>
                                                        </TextRun>
                                                    </TextRuns>
                                                    <Style>
                                                        <TextAlign>Center</TextAlign>
                                                    </Style>
                                                </Paragraph>
                                            </Paragraphs>
                                            <!--默认名称-->
                                            <rd:DefaultName>Textbox1</rd:DefaultName>
                                            <Style>
                                                <!--边框:实线-->
                                                <Border>
                                                    <Style>Solid</Style>
                                                </Border>
                                                <!--垂直对齐:中间-->
                                                <VerticalAlign>Middle</VerticalAlign>
                                                <!--左边距-->
                                                <PaddingLeft>2pt</PaddingLeft>
                                                <PaddingRight>2pt</PaddingRight>
                                            </Style>
                                        </TextBox>
                                    </CellContents>
                                </TablixCell>
                            </TablixCells>
                        </TablixRow>
                        
                        <TablixRow>
                            <Height>0.26747in</Height>
                            <TablixCells>
                                <TablixCell>
                                    <!--单元格内容-->
                                    <CellContents>
                                        <TextBox Name="产品型号">
                                            <!--可增长-->
                                            <CanGrow>true</CanGrow>
                                            <!--保持一致-->
                                            <KeepTogether>true</KeepTogether>
                                            <!--段落-->
                                            <Paragraphs>
                                                <Paragraph>
                                                    <TextRuns>
                                                        <TextRun>
                                                            <Value>=Fields!产品型号.Value</Value>
                                                            <!--样式-->
                                                            <Style>
                                                                <FontFamily>宋体</FontFamily>
                                                            </Style>
                                                        </TextRun>
                                                    </TextRuns>
                                                    <Style>
                                                        <TextAlign>Center</TextAlign>
                                                    </Style>
                                                </Paragraph>
                                            </Paragraphs>
                                                                                        <!--默认名称-->
                                            <rd:DefaultName>产品型号</rd:DefaultName>
                                            <Style>
                                                <!--边框:实线-->
                                                <Border>
                                                    <Style>Solid</Style>
                                                </Border>
                                                <!--垂直对齐:中间-->
                                                <VerticalAlign>Middle</VerticalAlign>
                                                <!--左边距-->
                                                <PaddingLeft>2pt</PaddingLeft>
                                                <PaddingRight>2pt</PaddingRight>
                                            </Style>
                                        </TextBox>
                                    </CellContents>
                                </TablixCell>
                            </TablixCells>
                        </TablixRow>
                    </TabLixRows>
                </TabliBody>
                <!--表阵 列层次结构-->
                <TablixColumnHierarchy>
                    <!--表阵 列成员-->
                    <TablixMembers>
                        <TablixMember />
                    </TablixMembers>
                </TablixColumnHierarchy>
                <!--表阵行层次结构-->
                <TablixRowHierarchy>
                    <TablixMembers>
                        <TablixMember>
                            <!--固定数据-->
                            <FixedData>true</FixedData>
                            <!--保持组-->
                            <KeepWithGroup>After</KeepWithGroup>
                            <!--在新的页-->
                            <RepeatOnNewPage>true</RepeatOnNewPage>
                        </TablixMember>
                        <!--表阵成员 -->
                        <TablixMember>
                            <Group Name="详细信息" />
                            <TablixMembers>
                                <TablixMember />
                            </TablixMembers>
                        </TablixMember>
                    </TablixMembers>
                </TablixRowHierarchy>
                <!--数据集名称-->
                <DataSetName>烧成车间日报表</DataSetName>
                <Top>0.07056cm</Top>
                <Left>0.5cm</Left>
                <Height>1.30584cm</Height>
                <Width>19.89838cm</Width>
                <Style>
                    <Border>
                        <Style>None</Style>
                    </Border>
                </Style>
            </Tablix>
        </ReportItems>
        <Height>0.59376in</Height>
    </body>
<!--报表参数-->
<ReportParameters>
    <ReportParameter Name="Title">
        <DataType>String</DataType>
        <!--允许空值-->
        <Nullable>true</Nullable>
        <!--允许空白-->
        <AllowBlank>true</AllowBlank>
        <Prompt>ReportParameter1</Prompt>
    </ReportParameter>
    <ReportParameter Name="Line">
        <DataType>String</DataType>
        <Nullable>true</Nullable>
        <AllowBlank>true</AllowBlank>
        <Prompt>ReportParameter1</Prompt>
    </ReportParameter>
    <ReportParameter Name="WorkShop">
        <DataType>String</DataType>
        <Nullable>true</Nullable>
        <AllowBlank>true</AllowBlank>
        <Prompt>ReportParameter1</Prompt>
    </ReportParameter>
</ReportParameters>
<Width>8.18603in</Width>
<!--页面-->
<Page>
    <!--页头信息-->
    <PageHeader>
      <Height>1.50812cm</Height>
      <PrintOnFirstPage>true</PrintOnFirstPage>
      <PrintOnLastPage>true</PrintOnLastPage>
      <ReportItems>
        <Textbox Name="Textbox00">
          <CanGrow>true</CanGrow>
          <KeepTogether>true</KeepTogether>
          <Paragraphs>
            <Paragraph>
              <TextRuns>
                <TextRun>
                  <Value>=Parameters!Title.Value</Value>
                  <Style>
                    <FontFamily>宋体</FontFamily>
                    <FontSize>12pt</FontSize>
                    <FontWeight>Bold</FontWeight>
                  </Style>
                </TextRun>
              </TextRuns>
              <Style>
                <TextAlign>Center</TextAlign>
              </Style>
            </Paragraph>
          </Paragraphs>
          <rd:DefaultName>Textbox00</rd:DefaultName>
          <Top>0.05cm</Top>
          <Left>0.5cm</Left>
          <Height>0.67938cm</Height>
          <Width>19.99843cm</Width>
          <Style>
            <Border>
              <Style>None</Style>
            </Border>
            <VerticalAlign>Middle</VerticalAlign>
            <PaddingLeft>2pt</PaddingLeft>
            <PaddingRight>2pt</PaddingRight>
            <PaddingTop>2pt</PaddingTop>
            <PaddingBottom>2pt</PaddingBottom>
          </Style>
        </Textbox>
        <Textbox Name="Textbox01">
          <CanGrow>true</CanGrow>
          <KeepTogether>true</KeepTogether>
          <Paragraphs>
            <Paragraph>
              <TextRuns>
                <TextRun>
                  <Value>生产线:</Value>
                  <Style>
                    <FontFamily>宋体</FontFamily>
                  </Style>
                </TextRun>
                <TextRun>
                  <Value>=Parameters!Line.Value</Value>
                  <Style>
                    <FontFamily>宋体</FontFamily>
                  </Style>
                </TextRun>
              </TextRuns>
              <Style>
                <TextAlign>Left</TextAlign>
              </Style>
            </Paragraph>
          </Paragraphs>
          <rd:DefaultName>Textbox01</rd:DefaultName>
          <Top>0.76466cm</Top>
          <Left>0.5cm</Left>
          <Height>0.6cm</Height>
          <Width>3.46197cm</Width>
          <ZIndex>1</ZIndex>
          <Style>
            <Border>
              <Style>None</Style>
            </Border>
            <VerticalAlign>Middle</VerticalAlign>
            <PaddingLeft>2pt</PaddingLeft>
            <PaddingRight>2pt</PaddingRight>
            <PaddingTop>2pt</PaddingTop>
            <PaddingBottom>2pt</PaddingBottom>
          </Style>
        </Textbox>
        <Textbox Name="Textbox02">
          <CanGrow>true</CanGrow>
          <KeepTogether>true</KeepTogether>
          <Paragraphs>
            <Paragraph>
              <TextRuns>
                <TextRun>
                  <Value>=Parameters!WorkShop.Value</Value>
                  <Style>
                    <FontFamily>宋体</FontFamily>
                  </Style>
                </TextRun>
              </TextRuns>
              <Style>
                <TextAlign>Left</TextAlign>
              </Style>
            </Paragraph>
          </Paragraphs>
          <rd:DefaultName>Textbox02</rd:DefaultName>
          <Top>0.76466cm</Top>
          <Left>3.96197cm</Left>
          <Height>0.6cm</Height>
          <Width>16.53646cm</Width>
          <ZIndex>2</ZIndex>
          <Style>
            <Border>
              <Style>None</Style>
            </Border>
            <VerticalAlign>Middle</VerticalAlign>
            <PaddingLeft>2pt</PaddingLeft>
            <PaddingRight>2pt</PaddingRight>
            <PaddingTop>2pt</PaddingTop>
            <PaddingBottom>2pt</PaddingBottom>
          </Style>
        </Textbox>
      </ReportItems>
      <Style>
        <Border>
          <Style>None</Style>
        </Border>
      </Style>
    </PageHeader>

    <!--页脚-->
    <PageFooter>
      <Height>0.87313cm</Height>
      <PrintOnFirstPage>true</PrintOnFirstPage>
      <PrintOnLastPage>true</PrintOnLastPage>
      <ReportItems>
        <Textbox Name="Textbox03">
          <CanGrow>true</CanGrow>
          <KeepTogether>true</KeepTogether>
          <Paragraphs>
            <Paragraph>
              <TextRuns>
                <TextRun>
                  <Value>="第" &amp; Globals!PageNumber &amp; "页 共" &amp; Globals!TotalPages &amp; "页"</Value>
                  <Style>
                    <FontFamily>宋体</FontFamily>
                    <FontSize>9pt</FontSize>
                  </Style>
                </TextRun>
              </TextRuns>
              <Style>
                <TextAlign>Center</TextAlign>
              </Style>
            </Paragraph>
          </Paragraphs>
          <rd:DefaultName>Textbox03</rd:DefaultName>
          <Top>0.1175cm</Top>
          <Left>0.39704cm</Left>
          <Height>0.6cm</Height>
          <Width>19.99843cm</Width>
          <Style>
            <Border>
              <Style>None</Style>
            </Border>
            <VerticalAlign>Middle</VerticalAlign>
            <PaddingLeft>2pt</PaddingLeft>
            <PaddingRight>2pt</PaddingRight>
            <PaddingTop>2pt</PaddingTop>
            <PaddingBottom>2pt</PaddingBottom>
          </Style>
        </Textbox>
      </ReportItems>
      <Style>
        <Border>
          <Style>None</Style>
        </Border>
      </Style>
    </PageFooter>
    <PageHeight>29.7cm</PageHeight>
    <PageWidth>21cm</PageWidth>
    <LeftMargin>0cm</LeftMargin>
    <RightMargin>0cm</RightMargin>
    <TopMargin>1cm</TopMargin>
    <BottomMargin>1cm</BottomMargin>
    <ColumnSpacing>0.13cm</ColumnSpacing>
</page>
<rd:ReportUnitType>Cm</rd:ReportUnitType>
</Report>

 

 

 

posted @ 2019-12-03 08:34  enych  阅读(384)  评论(0编辑  收藏  举报