visual-studio-2012 - ReportViewer未显示数据

  显示原文与译文双语对照的内容
0 0

我尝试在 Visual Studio 2012中使用ReportViewer添加报告,SQL Server 2005. 我正在使用 Visual Basic语言。

到目前为止,我已经尝试了这个代码,但没有显示我想要的数据

Imports Microsoft.Reporting.WinForms
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
 Dim rds As New ReportDataSource("DataSet1")
 Me.ReportViewer1.LocalReport.ReportPath ="C:UsersacerDocumentsVisual Studio 2012ProjectsWindowsApplication1WindowsApplication1Report1.rdlc"
 Me.ReportViewer1.LocalReport.DataSources.Clear()
 Me.ReportViewer1.LocalReport.DataSources.Add(rds)
 Me.ReportViewer1.RefreshReport()
End Sub
End Class

谁能告诉我怎么修复这个问题? 多谢了

时间:原作者:1个回答

0 0

Supossing,你的数据集包含一个或者多个数据表,你将缺少要在报表上显示的DataTable 。

Dim rds As New ReportDataSource("DataSet1", ds.Tables(0))

从代码中看到的,你没有任何任何数据源都从中检索数据的任何数据源。 下面的代码演示如何从数据库表检索数据并将它的显示到 ReportViewer

Dim strConnectionString As String ="Your connection string here"
Dim ds As New DataSet()
Dim da As New SqlDataAdapter()
Dim cmd As New SqlCommand("SELECT * FROM YourTable")
cmd.CommandType = CommandType.Text
cmd.Connection = New SqlConnection(strConnectionString)
da.SelectCommand = cmd
da.Fill(ds,"DataSet1")
Dim rds As New ReportDataSource("DataSet1", ds.Tables(0))
Me.ReportViewer1.LocalReport.ReportPath ="C:UsersacerDocumentsVisual Studio 2012ProjectsWindowsApplication1WindowsApplication1Report1.rdlc"
Me.ReportViewer1.LocalReport.DataSources.Clear()
Me.ReportViewer1.LocalReport.DataSources.Add(rds)
Me.ReportViewer1.RefreshReport()
原作者:
...