我尝试在Visual Studio 2012,SQL Server 2005中使用ReportViewer添加报表。我使用的是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:\Users\acer\Documents\Visual Studio 2012\Projects\WindowsApplication1\WindowsApplication1\Report1.rdlc"
Me.ReportViewer1.LocalReport.DataSources.Clear()
Me.ReportViewer1.LocalReport.DataSources.Add(rds)
Me.ReportViewer1.RefreshReport()
End Sub
End Class
有谁能告诉我如何解决这个问题?非常感谢
答案 0 :(得分:1)
假设您的DataSet包含一个或多个DataTable,您缺少要在报告上显示的DataTable。
Dim rds As New ReportDataSource("DataSet1", ds.Tables(0))
从我在您的代码中看到的,您没有任何DataTable,也没有任何从您检索数据的源。 以下代码显示了如何从数据库表中检索数据并将其显示在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:\Users\acer\Documents\Visual Studio 2012\Projects\WindowsApplication1\WindowsApplication1\Report1.rdlc"
Me.ReportViewer1.LocalReport.DataSources.Clear()
Me.ReportViewer1.LocalReport.DataSources.Add(rds)
Me.ReportViewer1.RefreshReport()
答案 1 :(得分:0)
再次配置数据源和reportview。首先转到ADD Datasoure然后选择数据库然后单击下一个然后选择数据集然后再次单击下一步 然后检查两个表和视图然后完成...然后选择报告视图然后单击新设计然后完成然后选择报告然后希望如此enter image description here