我现在要开发个程序,.net c#,数据库在广域网上,用webservice连接的,查询返回的是个dataset,要求用这个dataset作为报表的打印数据源,问题是我使用本地数据源就报错:该数据集不含报表.这个要怎么解决.我代码是这样写的:print1.Load("print.rpt");
print1.Refresh();
print1.SetDataSource(dataSet2.Tables[0]);<---该数据集不含报表
crystalReportViewer1.ReportSource = print1;
crystalReportViewer1.Refresh();
crystalReportViewer1.Update();print1是个printdoc看了很多都是用xsd的,但我不知道怎么将dataset的里的数据转换到xsd里面.希望各位大侠能给些详细的代码,或者告诉我需要哪些控件,总之尽量详细,或者有更好的方法,谢谢,在线等
print1.Refresh();
print1.SetDataSource(dataSet2.Tables[0]);<---该数据集不含报表
crystalReportViewer1.ReportSource = print1;
crystalReportViewer1.Refresh();
crystalReportViewer1.Update();print1是个printdoc看了很多都是用xsd的,但我不知道怎么将dataset的里的数据转换到xsd里面.希望各位大侠能给些详细的代码,或者告诉我需要哪些控件,总之尽量详细,或者有更好的方法,谢谢,在线等
print1.Load("print.rpt");這句里的“print.rpt”報表文件的數據源來自何方??建議樓主先找個例子看看。。
2.创建一个.rpt文件并指向我们前面创建的dataset
3.在.aspx页面上放置Crystal Report Viewer控件,设定它的属性指向上一步创建的.rpt文件。
4.在code behind page中,书写连接数据库的函数
5. 加上databind方法。 下面举例
创建一个设计时的dataset去定义Reports的Fielsds.
1)在"Solution Explorer"右击,选择"Add" --> select "Add New Item--> Select "DataSet"
2) 从"Server Explorer"面板中的"SQL Server"中拖进"Stores"表
3) 这将在dataset中创建一个"Stores" table
用这种方法创建的.xsd文件仅仅包含了field的定义,里面没有任何数据。需要你创建一个与数据库的链接并且将数据填充进去。创建.rpt文件
4)创建一个.rpt文件。与前面唯一不同的是不通过Crystal Report得到表,我们将用dataset来创建它。
5)建立.rpt文件后,右击"Details" section,选择"Add/Remove Database"
6) 在"Database Expert"窗口,展开"Project Data",展开"ADO.NET DataSet","DataSet1", 选择 "Stores" table.
7)点击">"将"Stores" table包括进"Selected Tables"
8) 接下来设定report的布局。调用
Sub BindReport()
Dim myConnection As New SqlClient.SqlConnection()
myConnection.ConnectionString= "server= (local);database=pubs;Trusted_Connection=yes"
Dim MyCommand As New SqlClient.SqlCommand()
MyCommand.Connection = myConnection
MyCommand.CommandText = "Select * from Stores"
MyCommand.CommandType = CommandType.Text Dim MyDA As New SqlClient.SqlDataAdapter()
MyDA.SelectCommand = MyCommand Dim myDS As New Dataset1()
'This is our DataSet created at Design Time
MyDA.Fill(myDS, "Stores")
'You have to use the same name as that of your Dataset that you created during design time
Dim oRpt As New CrystalReport1()
' This is the Crystal Report file created at Design Time
oRpt.SetDataSource(myDS)
' Set the SetDataSource property of the Report to the Dataset
CrystalReportViewer1.ReportSource = oRpt
' Set the Crystal Report Viewer's property to the oRpt Report object that we created
End Sub
http://dev.csdn.net/article/26/26646.shtm该 C# .NET Windows 程序演示了如何创建数据集,并将图像添加到数据集,以及在运行时将数据集传递到子报表。
利用数据集在水晶报表中显示图像的 .NET 程序教程
http://dev.csdn.net/article/26/26646.shtm
===========================DataSet CreateData()
{
DataSet data = new DataSet();
data.Tables.Add("Images");
data.Tables[0].Columns.Add("Country", System.Type.GetType("System.String"));
data.Tables[0].Columns.Add("img", System.Type.GetType("System.Byte[]"));
data.WriteXmlSchema(Directory.GetCurrentDirectory() + "\\DynamicImage.xsd");
}
因为print1.Load("http://11.20.31.1/ReportServices.asmx");这种方式无法运行.
用crystalReportViewer1.ReportSource="http://11.20.31.1/ReportServices.asmx"可以,但就无法设置数据源了(不知如何设置),
请楼主帮忙,谢谢