C# 将SQL结果发送到Crystal Reports
我有一个运行SQL查询的程序,我想将它报告给crystal report viewer。我收到错误信息:C# 将SQL结果发送到Crystal Reports,c#,sql,sql-server,vb.net,crystal-reports,C#,Sql,Sql Server,Vb.net,Crystal Reports,我有一个运行SQL查询的程序,我想将它报告给crystal report viewer。我收到错误信息: 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"
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()
非常感谢您的帮助在设置数据源之前,您需要在objRpt中加载报告文件
objRpt.Loadfilepath感谢您的回复。我应用了您的建议,但它不起作用。您需要在设计时将数据源应用于报告。将SQL输出存储在dataset中,并将dataset转换为XML,并在设计报告时将XML应用于Crystal报告。所以,下次运行代码时,XML会自动生成crystal报表的任何应用作为输入数据表。