2011-04-22 66 views
1

我有一個rdlc報告,顯示從Microsoft SQL 2008數據庫中的單個文本字段檢索到的轉錄信息。該報告很簡單,它由一個簡短的標題和一個包含單個文本框的正文組成。我們遇到的問題是部分報告數據被切斷。沒有錯誤信息只是切斷。經過一些測試,我們確定文本框切斷了大約32,000個字符。在這個發現之後,我做了一些研究,我發現唯一有用的東西是對msdn的引用social.msdn 我們正在運行的一些轉錄包含500,000個字符,我們無法知道它是否不會增加。是否有任何解決方法似乎是報告的文本框32,000個字符的限制?如何在RDLC文本框中顯示大量數據

回答

1

我想出的解決方案是編寫一些T-SQL來將大塊文本 分解成更小的部分,然後返回一個包含每行30,000個char文本塊的行的表。然後在報告中將我的文本框放在一個列表中。 以下是SQL

declare @transcriptionBody TABLE 
(
    SegmentNumber int identity(1,1), 
    BodyPart nvarchar(max) 
) 
declare 
    @bodyPart varchar(max), 
    @body nvarchar(max), 
    @indexToLastNewLineInBodyPart int, 
    @lenOfBody int, 
    @MAX_CHARACTERS int, 
    @numberOfCharactersLeftInString int, 
    @position int 

set @MAX_CHARACTERS = 30000 
set @indexToLastNewLineInBodyPart = 0 
set @numberOfCharactersLeftInString = 0 
set @position = 0 

/* 
* Get the long string of characters from your database. In this example the 
* [Body] field is a text field. 
*/ 
select @body = Body from [Transcription] with(nolock) where Id = @TranscriptionId 
set @lenOfBody = len(@body) 

/* 
* Loop through the @body variable chopping up the string into managable chuncks 
* and inserting those chuncks into a table variable called @transcriptionBody. 
* The loop exists when the 
*/ 
while (@position < @lenOfBody) 
begin 

    /* 
    * If the transcription body is less than 30,000 then insert it into 
    * our table variable and return. 
    */ 
    if (@lenOfBody <= @MAX_CHARACTERS and @position = 0) 
    begin 
     insert into @transcriptionBody(BodyPart) values(@body) 
     set @position = @lenOfBody 
    end 

    /* 
    * Otherwise we need do the following 
    * 1. Get the number of chars in the string starting from the input start index. 
    * 2. If the number of chars in the string is > than the max allowable chars then 
    *  substring off the first 30,000 chars into a body part. 
    *  
    *  2a. Now have a string consisting of 30,000 chars but you have no idea where it 
    *   cut off (it could be in the middle of a word). So you now need to get the 
    *   index of the last newline and re-break the string on that.Then insert it 
    *   into the table variable and set the position. 
    * 
    * 3. If the number of chars in the string IS NOT > than the max allowable chars 
    *  then substring off the remaining chars into a body part and insert it into our 
    *  table variable 
    */ 
    else 
    begin 
     -- 1. 
     select @numberOfCharactersLeftInString = (@position - @lenOfBody) * -1 

     -- 2. 
     if (@numberOfCharactersLeftInString > @MAX_CHARACTERS) 
     begin 
      select @bodyPart = substring(@body, @position, @MAX_CHARACTERS) 

      -- 2a. 
      select @indexToLastNewLineInBodyPart = Len(@bodyPart) - charindex(char(13)+char(10),reverse(@bodyPart)) 
      if (@indexToLastNewLineInBodyPart > 0) 
      begin 
       select @bodyPart = substring(@bodyPart,@position,@indexToLastNewLineInBodyPart) 
       insert into @transcriptionBody(BodyPart) values(@bodyPart) 
       select @position = @position + len(@bodyPart) 
      end  
     end 
     else 
     begin 
      select @bodyPart = substring(@body, @position, @numberOfCharactersLeftInString) 
      insert into @transcriptionBody(BodyPart) values(@bodyPart) 
      select @position = @position + len(@bodyPart) 
     end 
    end 
end 
select * from @transcriptionBody order by SegmentNumber