发送SQL结果到水晶报表

本文关键字:水晶 报表 结果 SQL 发送 | 更新日期: 2023-09-27 18:16:51

我有一个运行SQL查询的程序,我想把它报告给一个水晶报表查看器。我收到错误:

DataSourceException was unhandled: The report has no tables
我的代码是:
Dim con As New SqlConnection("Data Source=Server;Initial Catalog=Main;Persist Security Info=True;User ID=login;Password=password")
        Dim CategoryAdapter As New SqlDataAdapter("SELECT firstname, lastname, add1 from Customers where dtcreated between @startdate and @enddate", con)
        Dim ProductData As New DataSet()
        con.Open()
        CategoryAdapter.SelectCommand.CommandTimeout = 130
        CategoryAdapter.SelectCommand.Parameters.AddWithValue("@Startdate", DateTimePicker1.Value)
        CategoryAdapter.SelectCommand.Parameters.AddWithValue("@Enddate", DateTimePicker2.Value)
        CategoryAdapter.Fill(ProductData)

        Dim objRpt As New CrystalReport1
        objRpt.SetDataSource(ProductData.Tables(0))
        CrystalReportViewer1.ReportSource = objRpt
        CrystalReportViewer1.Refresh()
        Return ProductData.Tables(0)
        con.Close()
        con.Dispose()

感谢您的帮助

发送SQL结果到水晶报表

您需要在objRpt中加载报告文件才能设置数据源objRpt .Load (filepath)