【问题标题】:How to create RDLC report from dynamic query in SQL Server Express如何从 SQL Server Express 中的动态查询创建 RDLC 报告
【发布时间】:2012-12-19 05:25:13
【问题描述】:

我无法从此过程创建 rdlc 报告,我正在使用报告查看器,但是当我选择该过程时,它不显示任何列名,但我的过程返回 7 列。如何创建报告请帮忙?我正在 vb.net 中创建报告

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

【问题讨论】:

    标签: sql vb.net sql-server-express


    【解决方案1】:

    创建一个映射到存储过程返回的字段的类

    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 报告而不是映射到存储过程时,将其映射到对象数据源并选择您刚刚创建的类。将此类中的文件用作您的报告的字段。

    在按钮显示报告中,您可以使用以下代码显示您的报告

    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
    

    【讨论】:

      猜你喜欢
      • 2014-03-30
      • 2019-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多