看了 Carlwave-陆飞(Fei.Lu) 的VS2005+SQL2005 Reporting Service动态绑定报表(Web) ,我认为也许他的方案可行,但并不是很好。所以我找了一些资料,发现通过WebService动态生成的DataSet是可以绑定到Reporting Services,这样也就满足了对DataSet的可操作性,也就是你可以在WebService中编程操作DataSet.
我的步骤是这样的:
1.首先创建一个WebSerivce,然后写了一个Web Method:
 [WebMethod]
    [WebMethod] public XmlDataDocument GetDataSource()
    public XmlDataDocument GetDataSource() {
    { string strCon;
        string strCon;
 DataSet ds = new DataSet();
        DataSet ds = new DataSet(); XmlDataDocument xmlDataDoc;
        XmlDataDocument xmlDataDoc;
 strCon = "Your Connection String";
        strCon = "Your Connection String"; 
         string selectText = "Your Select String";
        string selectText = "Your Select String";
 SqlDataAdapter dataAdapter = new SqlDataAdapter(selectText,strCon);
        SqlDataAdapter dataAdapter = new SqlDataAdapter(selectText,strCon); 
        
 try{
        try{ dataAdapter.Fill(ds);
        dataAdapter.Fill(ds);
 xmlDataDoc = new XmlDataDocument(ds);
        xmlDataDoc = new XmlDataDocument(ds); }
        } catch
        catch {
        { xmlDataDoc = null;
            xmlDataDoc = null; }
        } finally
        finally {
        { strCon = null;
            strCon = null; ds.Dispose();
            ds.Dispose(); }
        } return xmlDataDoc;
        return xmlDataDoc;
 }
    }我们可以注意到。这里使用了XmlDataDocument,还记得陆飞文章中提到了XML文档,我们需要受到手动修改它吗?其实是不需要的,我们可以通过XmlDataDocument关联到DataSet生成相应的XML
2.新建一个Reporting Services项目,注意时Reporting Serverices项目,不是Report Viewer控件,关于他们的区别,参见:
http://msdn2.microsoft.com/zh-cn/library/ms345248.aspx
然后在Shared Data Source里新建一个DataSource,指定Type为XML,Connection String 为你的WebSerivce,比如说 http://localhost/WebService/Service.asmx(你可能需要在IIS中部署WebService)
然后新建一个Report,指定Query String 为:
<Query xmlns="http://Eric.org/">
<SoapAction>http://Eric.org/GetDataSource</SoapAction>
</Query>
关于WebService的Query String语法,请参见:
http://msdn2.microsoft.com/en-us/library/ms345251.aspx
然后就可以取得数据了。
过程中,我遇到的一个问题是,如果在VS中创建的默认的WebService Namespace为http://tempuri.org/,Query String检查就会报错,你只要更改一个Namespace就可以了(如果说我改成了http://Eric.org)
这样做的好处显而易见,就是可以使用Reporting Services的可视化报表设计系统了。
好久不写文章了,向大家问个好:)
参考文章:
http://www.codeproject.com/aspnet/WebAndReportingServices.asp
 
                    
                 
                
 
 
    
 
         
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号