首页 > 解决方案 > 如何使用连接表创建 RDLC 报告?

问题描述

我正在尝试创建一个报告,该报告将显示我的表,该表具有来自不同表的连接,看起来像这样,

select * from tblproduct As p inner join tblbrand As b On p.bid = b.brandid inner Join tblclassification As c On p.cid = c.classid inner Join tblformulation As f On p.fid = f.formid inner Join tblgeneric As g On p.gid = g.genericid inner Join tbltype As t On p.tid = t.typeid

我的表由 8 列组成,其中 4 列是用于连接的列 ID,当我尝试显示到 datagridview 时,我可以成功使用查询,但是当我在 reportviewer 中尝试时,它不起作用并给我错误:"Object reference not sent to an instance of an object"。这是我试过的,

Public Class frmInventoryReport

    Public Property strReport2 As String
    Private Sub frmInventoryReport_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Me.tblproductTableAdapter.Fill(Me.groceryDataSet.tblproduct)
        Me.ReportViewer1.RefreshReport()

        Dim rptDataSource As New ReportDataSource

        Try
            With Me.ReportViewer1.LocalReport
                .ReportPath = "D:\VisualBasic\EELPOS - Copy\EELPOS\Report3.rdlc"
                .DataSources.Clear()
            End With

            Select Case strReport2
                Case "Report3"

                    Dim i As Integer = 0
                    Dim sqlQuery As String = "select * from tblproduct As p inner join tblbrand As b On p.bid = b.brandid inner Join tblclassification As c On p.cid = c.classid inner Join tblformulation As f On p.fid = f.formid inner Join tblgeneric As g On p.gid = g.genericid inner Join tbltype As t On p.tid = t.typeid"
                    Dim da As New MySqlDataAdapter(sqlQuery, cn)
                    Dim dt As DataTable = New DataTable()
                    While dr.Read
                        dt.Rows.Add(i, dr.Item("barcode").ToString, dr.Item("generic").ToString, dr.Item("classification").ToString, dr.Item("type").ToString, dr.Item("formulation").ToString, dr.Item("price").ToString, dr.Item("qty").ToString)
                    End While
                    da.Fill(dt)

                    rptDataSource = New ReportDataSource("inventory", dt)

            End Select

            Me.ReportViewer1.LocalReport.DataSources.Add(rptDataSource)

        Catch ex As Exception
            MessageBox.Show(ex.Message, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try

        Me.ReportViewer1.RefreshReport()

    End Sub
End Class

正确的方法是什么?

标签: vb.netreportingrdlc

解决方案


推荐阅读