我现在要开发个程序,.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里面.希望各位大侠能给些详细的代码,或者告诉我需要哪些控件,总之尽量详细,或者有更好的方法,谢谢,在线等

解决方案 »

  1.   

    請問樓主:
    print1.Load("print.rpt");這句里的“print.rpt”報表文件的數據源來自何方??建議樓主先找個例子看看。。
      

  2.   

    哦,这个就是我的问题了.我第一次提问可能说不清楚,就是问这个rpt怎么使用这个返回的数据集
      

  3.   

    偶收集的,雖然代碼是VB.net,可參考一下:===============================1.创建一个设计时的dataset
    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
      

  4.   

    这个我看懂了,但是具体到我的问题就是我用webservice查询返回的就是一个dataset2,我想把rpt的数据源直接就设为这个dataset2却不知道怎么弄,而且不允许我强制转换,有办法么?
      

  5.   

    还是说报表必须使用xsd的数据集,那么我返回的dataset2要强转成xsd的要怎么转???
      

  6.   

    看看下面這個例子,對樓主應該會有幫助:利用数据集在水晶报表中显示图像的 .NET 程序教程  
    http://dev.csdn.net/article/26/26646.shtm该 C# .NET Windows 程序演示了如何创建数据集,并将图像添加到数据集,以及在运行时将数据集传递到子报表。
      

  7.   

    我再说清楚点吧,水晶报表这边要求使用xsd的数据集才能在数据库专家里面看到,但是我在webservice里面查询返回的结果集是dataset的,两者无法转换,我将webservice返回值也转换成xsd集后也无法转换(一个是movestore.dataset1,一个是movestore.localhost.dataset1)问大侠是否有办法转换,或者将回来的xsd转换成本地数据集xsd,oh,我的是2005
      

  8.   

    上面例子里有個CreateData函數创建数据集啊~2005與2003應該差別不太大吧。。===========================
    利用数据集在水晶报表中显示图像的 .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");
        }
      

  9.   

    有头绪了,刚发现可以直接引用webservice里面的xsd,这下简单多了,还是谢谢BubbleKitty(BK | 心若在,梦就在:)) 了
      

  10.   

    请问您webservice中的报表服务如何载入的?
    因为print1.Load("http://11.20.31.1/ReportServices.asmx");这种方式无法运行.
    用crystalReportViewer1.ReportSource="http://11.20.31.1/ReportServices.asmx"可以,但就无法设置数据源了(不知如何设置),
    请楼主帮忙,谢谢