vb.net - 如何使用连接表创建 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
正确的方法是什么?
解决方案
推荐阅读
- swift - GeoFire没有快速显示输入区域
- ssl - HTTPS 连接在几分钟后停止工作
- asterisk - 如果星号队列成员分机没有接听电话,我想发送通知电子邮件
- c# - PUN 2 未连接玩家
- reactjs - React - 无法读取未定义的属性“setState”
- javascript - 如何在使用 javascript 中的 RegExp 删除表情符号后删除剩余的 \u200d?
- python - 如何在 Python 中搜索序列中的值?
- ruby-on-rails - 删除推送到 Heroku 的旧迁移
- aws-lambda - 如何使用无服务器框架管理生产、测试和开发环境
- python - ModuleNotFoundError: pip install 后没有名为“tensorflow”的模块——遵循 TF 官方安装文档