我尝试在VisualStudio2012SQLServer 2005中使用ReportViewer添加报表。我使用的是Visual语言。
到目前为止,我已经尝试了这段代码,并且没有显示我想要的数据
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有人能教我怎么修吗?非常感谢
发布于 2015-05-28 07:40:30
如果您的DataSet包含一个或多个DataTables,则缺少要在报表上显示的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()发布于 2017-10-15 10:09:27
再次配置Datasource和reportview .Firstly,转到ADD,然后选择数据库,然后单击next,然后再次单击next,然后检查表和视图,,然后完成.然后选择report视图,然后单击new,然后完成,然后选择report,然后希望如此在这里输入图像描述
https://stackoverflow.com/questions/30497752
复制相似问题