2012-12-19 53 views
0

我無法通過此過程創建rdlc報告,我使用的是報告查看器,但是當我選擇該過程時,它不顯示任何列名稱,但是我的過程返回7列。我如何創建報告請幫助?我在vb.net如何在SQL Server Express中通過動態查詢創建RDLC報告

ALTER PROCEDURE Pr_getAcceptedOnDateReport 
@date date 
AS 
SET FMTONLY OFF 
DECLARE @SQL varchar(MAX) 
DECLARE @antiHIV bit 
DECLARE @HBsAg bit 
DECLARE @IGMHBCore bit 
DECLARE @NAT bit 
DECLARE @Malaria bit 
DECLARE @TotalHBCore bit 
DECLARE @Syphilis bit 
DECLARE @HCV bit 
DECLARE @ICT bit 
DECLARE @DCT bit 
DECLARE @Antibody bit 

Select @antiHIV=[HIV1/2 screen Reactive], 
@IGMHBCore=[IgM HBcore Reactive], 
@HBsAg=[HBsAg Screen Reactive], 
@NAT= [NAT Reactive], 
@Malaria=[Malaria Screen Reactive], 
@TotalHBCore=[Total HBcore Reactive], 
@Syphilis=[Syphilis Screen Reactive], 
@HCV=[HCV screen Reactive], 
@ICT=[ICT Positive], 
@DCT= [DCT Positive], 
@Antibody= [Antibody Screen Positive] 
from m_rejectionRules where deleted=0 

DECLARE @sql1 nvarchar(4000)  

Select @sql1='Select t.donorid, t.donorname, t.sampleid, t.customid,t.bagtype,t.bagnumber, t.segmentno from ttidetail t, m_donor m 
where t.donorid=m.donorid 
AND CONVERT(date, m.RDate) =''' + cast(@date as varchar(100)) + '''' 

IF @antiHIV='True' 
BEGIN 
SELECT @sql1 = @sql1 + ' AND t.antiHIV like ' + ''''+ 'Non%Reactive'+'''' 
END 
IF @HBsAg='True' 
BEGIN 
SELECT @sql1 = @sql1 + ' AND t.HBsAg like '+ ''''+ 'Non%Reactive'+'''' 
END 
IF @IGMHBCore='True' 
BEGIN 
SELECT @sql1 = @sql1 + ' AND t.IGM_antiHBC like '+ ''''+ 'Non%Reactive'+'''' 
END 
IF @NAT='True' 
BEGIN 
SELECT @sql1 = @sql1 + ' AND t.NAT_HIV1 like '+ ''''+ 'Non%Reactive'+'''' 
END 
IF @Malaria='True' 
BEGIN 
SELECT @sql1 = @sql1 + ' AND t.malariaScreen like '+ ''''+ 'Non%Reactive'+'''' 
END 
IF @TotalHBCore='True' 
BEGIN 
SELECT @sql1 = @sql1 + ' AND t.totalAnti_HBC like '+ ''''+ 'Non%Reactive'+'''' 
END 

IF @Syphilis='True' 
BEGIN 
SELECT @sql1 = @sql1 + ' AND t.SyphilisScreen like '+ ''''+ 'Non%Reactive'+'''' 
END 


EXEC sp_executesql @sql1 

回答

0

創建報告創建映射到您的存儲過程

Public Class ReportData 

Property donorid AS Integer = 0 
Property donorname as string = string.empty 
Property sampleid as integer = 0 
Property customid as integer = 0 
Property bagtype as string = string.empty 
Property bagnumber as integer = 0 
Property segmentno as integer = 0 

End Class 

假設你有返回使用上述數據集函數返回你的領域類查詢時,我將把它作爲DS

*最重要* 當創建的,而不是你的映射RDLC報告,storedprocdure映射它的對象數據源,並選擇類,你剛創建。將此類中的文件用作報告的字段。

在按鈕顯示報告,你可以使用下面的代碼顯示報告

Private Sub ShowReport() 
    Dim dsL As DataSet = New DataSet() 
    dsL = GetReportData() ' Function which will get the data from the SQL Query 

    Dim rds As ReportDataSource = New ReportDataSource() 
    rds.Name = "ReportDS" ' Change to what you will be using when creating an objectdatasource 
    rds.Value = dsL.Tables(0) 
    With rvReport ' Name of the report control on the form 
     .Reset() 
     .ProcessingMode = ProcessingMode.Local 
     .LocalReport.DataSources.Clear() 
     .Visible = True 
     .LocalReport.ReportPath = reportPath 
     .LocalReport.DataSources.Add(rds) 


     ' If you have any parameters you can pass them here 
     Dim rptParameters As New List(Of ReportParameter)() 
     With rptParameters 
      .Add(New ReportParameter("Title", 
       String.Format("{0} Grid For Period {1} To {2}", 
        gridType, 
        FormatDateTime(startDate, DateFormat.ShortDate), 
        FormatDateTime(endDate, DateFormat.ShortDate)))) 
      .Add(New ReportParameter("SubTitle", String.Format("Program: {0}", ucProgram.Text))) 
      .Add(New ReportParameter("StartDate", startDate)) 
      .Add(New ReportParameter("EndDate", endDate)) 
     End With 
     .LocalReport.SetParameters(rptParameters) 

     .RefreshReport() 
    End With 

End Sub