Rdlc報表由於reportviewer版本升級導致修改舊版報表後客戶端無法開啟
安裝VS2017後,reportviewer另外下載安裝的,繁體的,都沒找到簡體的。
修改原來的rdlc報表時,版本會不一樣,導致客戶端列印的時候報錯。
Microsoft.Reporting.WinForms.LocalProcessingException: An error occurred during local report processing. ---> Microsoft.Reporting.DefinitionInvalidException: The definition of the report '' is invalid. ---> Microsoft.ReportingServices.ReportProcessing.ReportProcessingException: The definition of this report is not valid or supported by this version of Reporting Services. The report definition may have been created with a later version of Reporting Services, or contain content that is not well-formed or not valid based on Reporting Services schemas. Details: The report definition has an invalid target namespace 'http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition' which cannot be upgraded.
檢視報表檔案的時候發現
<?xml version="1.0" encoding="utf-8"?> <Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">
名稱空間已經從
”http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition“
變成
”http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition“
為了和原來的版本保持一致,可以從報表檔案的程式碼裡面進行新增修改。
<TablixRows> <TablixRow> <Height>0.5cm</Height> <TablixCells> <TablixCell> <CellContents> <Textbox Name="textbox20"> <CanGrow>true</CanGrow> <KeepTogether>true</KeepTogether> <Paragraphs> <Paragraph> <TextRuns> <TextRun> <Value>="哈哈(" & First(Fields!ManageType.Value, "A") & ")"</Value> <Style> <FontFamily>宋體</FontFamily> </Style> </TextRun> </TextRuns> <Style /> </Paragraph> </Paragraphs> <rd:DefaultName>textbox20</rd:DefaultName> <Style> <BottomBorder> <Color>Black</Color> <Style>Solid</Style> <Width>1pt</Width> </BottomBorder> <PaddingLeft>2pt</PaddingLeft> <PaddingRight>2pt</PaddingRight> <PaddingTop>2pt</PaddingTop> <PaddingBottom>2pt</PaddingBottom> </Style> </Textbox> </CellContents> </TablixCell> <TablixCell> <CellContents> <Textbox Name="textbox21"> <CanGrow>true</CanGrow> <KeepTogether>true</KeepTogether> <Paragraphs> <Paragraph> <TextRuns> <TextRun> <Value>=format(First(Fields!PrescriptDate.Value, "A"),"yyyy年MM月dd日")</Value> <Style> <FontFamily>宋體</FontFamily> </Style> </TextRun> </TextRuns> <Style /> </Paragraph> </Paragraphs> <rd:DefaultName>textbox21</rd:DefaultName> <Style> <BottomBorder> <Color>Black</Color> <Style>Solid</Style> <Width>1pt</Width> </BottomBorder> <PaddingLeft>2pt</PaddingLeft> <PaddingRight>2pt</PaddingRight> <PaddingTop>2pt</PaddingTop> <PaddingBottom>2pt</PaddingBottom> </Style> </Textbox> <ColSpan>4</ColSpan> </CellContents> </TablixCell> <TablixCell /> <TablixCell /> <TablixCell /> </TablixCells> </TablixRow>
注意增加行要在 <TablixRowHierarchy>節點下增加 <TablixMember>。否則會提示行數量不對。
<TablixRowHierarchy> <TablixMembers> <TablixMember> <KeepWithGroup>After</KeepWithGroup> <KeepTogether>true</KeepTogether> </TablixMember> <TablixMember> <KeepWithGroup>After</KeepWithGroup> <KeepTogether>true</KeepTogether> </TablixMember>