且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将 DataTable 绑定到 RDLC 和 ReportViewer

更新时间:2022-05-08 02:00:06

需要检查的一些事项:测试报告"必须是报告设计器中使用的名称.它区分大小写.dt 也必须与报表设计器中使用的名称相匹配您的报告路径"的格式应为namespace.reportname.rdlc".区分大小写.

Some things to check: "Test Report" must be the name used in the report designer. It's case sensitive. The dt must match the name used in the report designer too "Your report Path" should be of the form "namespace.reportname.rdlc" . It's case sensitive.

我通常使用的方法使用一个额外的层,以 BindingSource 的形式如下:使用临时查询和 SqlDataAdapter 填充强类型数据集.将 Bindingsource 变暗并将其 DataSource 设置为数据集并将其 DataMember 设置为表名称.将 ReportDataSource 变暗并将其名称设置为报表设计器中使用的名称,并将其值设置为 BindingSource例如

The approach I normally use utilises an extra layer, in the form of a BindingSource as follows: Fill a strongly-typed dataset using the ad-hoc query and a SqlDataAdapter. Dim a Bindingsource and set its DataSource to the dataset and its DataMember to the table name. Dim a ReportDataSource and set its name to the name used in the report designer, and its value to the BindingSource eg

 Using cn As New SqlConnection(gcs)
        cn.Open()
        Dim sa As New SqlDataAdapter(sql, cn)
        sa.SelectCommand.CommandTimeout = cGlobals.ReportTimeout
        sa.Fill(ds, "Foos")
    End Using
    bs.DataSource = ds
    bs.DataMember = "Foos"
    Dim rds As New ReportDataSource
    rds.Name = "dsFooList_Foos"
    rds.Value = bs
    rv1.LocalReport.DataSources.Add(rds)

    Me.Show()
    rv1.RefreshReport()

编辑 2:在屏幕截图中的这一点,下拉数据源并选择您想要的数据源.然后它会出现在报表数据"窗口中,该窗口可能隐藏在查看"菜单中(只有在您处理报表时才会出现)然后您可以从工具箱中向报表添加一个表格,然后拖动从报表数据窗口到表格单元格的字段.

Edit 2: At the point in your screenshot, drop down the datasources and pick the one you want. It will then appear in the Report Data window, which may be hiding in the 'View' menu (it's only there when you're working with a report) Then you can add a Table to the report from the toolbox, and then drag the fields from the Report Data window to the table cells.