zoukankan      html  css  js  c++  java
  • sql2005 reporting service,我总算找到一个完全程序化绑定报表(ado.net dataset 绑定reprot)的方案,谁能再给我些其他建议呢? Carlwave

        想想还是放首页吧,希望更多的人来交流……
        花了很长时间研究reporting service,也看了N多文章和资料,但还是处于迷迷糊糊混沌混沌的状态。
        知道reporting service有很多强大的功能,也通过范例能过实现,但是对于报表的设计,最主要的是报表数据源和datasets的设计有点不是最理解,不过目前总算是找到一个解决方案,等整理好之后发出来给大家
        http://msdn2.microsoft.com/en-us/library/aa337091.aspx这篇文章讲述了如何用ado.net dataset作为数据源去绑定report。我按照范例做确实成功了。简略代码:
    Protected Sub Page_Init(ByVal sender As Object, _
                        ByVal e As System.EventArgs) Handles Me.Init

            If Not Page.IsPostBack Then

                'Set the processing mode for the ReportViewer to Local
                ReportViewer1.ProcessingMode = ProcessingMode.Local

                Dim localReport As LocalReport
                localReport = ReportViewer1.LocalReport

                localReport.ReportPath = "Reports\Default.rdlc"

                Dim dataset As New DataSet("Sales Order Detail")

                Dim salesOrderNumber As String = "SO43661"

                'Get the sales order data
                GetSalesOrderData(salesOrderNumber, dataset)

                'Create a report data source for the sales order data
                Dim dsSalesOrder As New ReportDataSource()
                dsSalesOrder.Name = "SalesOrder"
                dsSalesOrder.Value = dataset.Tables("SalesOrder")

                localReport.DataSources.Add(dsSalesOrder)

                'Get the sales order detail data
                GetSalesOrderDetailData(salesOrderNumber, dataset)

                'Create a report data source for the sales
                'order detail data
                Dim dsSalesOrderDetail As New ReportDataSource()
                dsSalesOrderDetail.Name = "SalesOrderDetail"
                dsSalesOrderDetail.Value = _
                    dataset.Tables("SalesOrderDetail")

                localReport.DataSources.Add(dsSalesOrderDetail)

                'Create a report parameter for the sales order number
                Dim rpSalesOrderNumber As New ReportParameter()
                rpSalesOrderNumber.Name = "SalesOrderNumber"
                rpSalesOrderNumber.Values.Add("SO43661")

                'Set the report parameters for the report
                Dim parameters() As ReportParameter = {rpSalesOrderNumber}
                localReport.SetParameters(parameters)

            End If

        End Sub

    但是问题的关键在于我不知道如何去设计这个基于xml的rdlc文件,在范例Sales Order Detail.rdlc中
    已经默认存在了  <DataSources>
        <DataSource Name="AdventureWorks">
          <DataSourceReference>AdventureWorks</DataSourceReference>
          <rd:DataSourceID>9d4e7b1f-0315-4083-8ff3-aa70c1fb2920</rd:DataSourceID>
        </DataSource>
      </DataSources>
    和    
        <DataSet Name="SalesOrderDetail">
          <Query>
            <rd:UseGenericDesigner>true</rd:UseGenericDesigner>
            <CommandText>SELECT      SOD.SalesOrderDetailID, SOD.OrderQty, SOD.UnitPrice,
                CASE WHEN SOD.UnitPriceDiscount IS NULL THEN 0 ELSE SOD.UnitPriceDiscount END AS UnitPriceDiscount,
                SOD.LineTotal, SOD.CarrierTrackingNumber, SOD.SalesOrderID, P.Name, P.ProductNumber
    FROM        Sales.SalesOrderDetail SOD INNER JOIN
                Production.Product P ON SOD.ProductID = P.ProductID INNER JOIN
                Sales.SalesOrderHeader SOH ON SOD.SalesOrderID = SOH.SalesOrderID
    WHERE       (SOH.SalesOrderNumber = @SalesOrderNumber)
    ORDER BY    SOD.SalesOrderDetailID</CommandText>
            <QueryParameters>
              <QueryParameter Name="@SalesOrderNumber">
                <Value>=Parameters!SalesOrderNumber.Value</Value>
              </QueryParameter>
            </QueryParameters>
            <Timeout>30</Timeout>
            <DataSourceName>AdventureWorks</DataSourceName>
          </Query>
          <Fields>
            <Field Name="SalesOrderDetailID">
              <rd:TypeName>System.Int32</rd:TypeName>
              <DataField>SalesOrderDetailID</DataField>
            </Field>
            <Field Name="OrderQty">
              <rd:TypeName>System.Int16</rd:TypeName>
              <DataField>OrderQty</DataField>
            </Field>
            <Field Name="UnitPrice">
              <rd:TypeName>System.Decimal</rd:TypeName>
              <DataField>UnitPrice</DataField>
            </Field>
            <Field Name="UnitPriceDiscount">
              <rd:TypeName>System.Decimal</rd:TypeName>
              <DataField>UnitPriceDiscount</DataField>
            </Field>
            <Field Name="LineTotal">
              <rd:TypeName>System.Decimal</rd:TypeName>
              <DataField>LineTotal</DataField>
            </Field>
            <Field Name="CarrierTrackingNumber">
              <rd:TypeName>System.String</rd:TypeName>
              <DataField>CarrierTrackingNumber</DataField>
            </Field>
            <Field Name="SalesOrderID">
              <rd:TypeName>System.Int32</rd:TypeName>
              <DataField>SalesOrderID</DataField>
            </Field>
            <Field Name="Name">
              <rd:TypeName>System.String</rd:TypeName>
              <DataField>Name</DataField>
            </Field>
            <Field Name="ProductNumber">
              <rd:TypeName>System.String</rd:TypeName>
              <DataField>ProductNumber</DataField>
            </Field>
          </Fields>
        </DataSet>
      </DataSets>
    就是因为在rdlc文件中包含了dataset才使结果是正确的,但是这样的rdlc文件是如何设计出来的呢?我已经发觉在rdlc文件中的连接都是不需要的,所以我可以手动写这个xml文件,我最终要达到的是能够在一个reportviewer上面通过传递参数动态的绑定不同的reports,目前就手工写的方法。

    谁也有研究过??大家讨论讨论,交流下经验。

  • 相关阅读:
    User-Introduction——介绍
    UserHow to Config
    DevHacking
    【转载】常备JS操作
    【转载】本地搜索服务全面评测
    User-Data config
    小知识:常用到的软件或服务及其使用的端口
    网页配色方案
    User-Validation User Guide
    Dev-Introduction
  • 原文地址:https://www.cnblogs.com/Carlwave/p/470590.html
Copyright © 2011-2022 走看看