搜了一下前面的帖子,看了一下blog,现已可以实现用pull的模式实现。但生成同样的报表,我用push模式,就还是提示我登陆失败。
文件夹该给的写权限我都给了。
连接字符串也正确,我用PULL模式的时候,就可以。用PUSH不明白了,高人们,给指点一下吧!!我的步骤:
1、生成一个数据集文件dataset1.xsd,并把sql server中的的一个表(SlinfoVwOfZb)托了进来,有字段xh,rq,sl,然后生成项目
2、添加CrystalReport1.rpt,并选择专家报表,从刚才生成的数据集中选择连接的内容,然后将字段完全添加,然后完成
3、添加一个新的webForm,然后添加CrystalReport View,命名为CustomerOrderCRViewer,在page_Load中写下面的代码
YabOA.Dataset1.SlinfoVwOfZbDataTable ds = new YabOA.Dataset1.SlinfoVwOfZbDataTable();
string connectString = ConfigurationSettings.AppSettings["CONNECTSTRING"];
SqlConnection MyConnection = new SqlConnection(connectString);
MyConnection.Open();
string sqlstring = "select xh,rq,sl from SlinfoVwOfZb"; SqlDataAdapter MyCommand = new SqlDataAdapter(sqlstring,MyConnection);

MyCommand.Fill(ds);
                            YabOA.CrystalReport1 cr1 = new YabOA.CrystalReport1();      
cr1.SetDataSource(ds);
                           //如果没有下面的这句,不报错,但自然也不会显示报表
this.CustomerOrderCRViewer.ReportSource = cr1;


MyConnection.Close();

解决方案 »

  1.   

    如果你用的是水晶报表的推模式,一般不用设置登陆信息,但是要这样写:obj.SetDataSource(this.ds.Tables["tablename"]);如果你写成了obj.SetDataSource(this.ds)就会有登陆框的。 如果你用的是水晶报表的拉模式,你就一定要写上登陆信息:crReportDocument = new OracleReport();   //Set the crConnectionInfo with the current values stored in the report
       crConnectionInfo = crReportDocument.Database.Tables[0].LogOnInfo.ConnectionInfo;   /* Populate the ConnectionInfo Objects Properties with the appropriate values for
       the ServerName, User ID, Password and DatabaseName. However, since Oracle 
       works on Schemas, Crystal Reports does not recognize or store a DatabaseName. 
       Therefore, the DatabaseName property must be set to a BLANK string. */
       crConnectionInfo.DatabaseName = "";
       crConnectionInfo.ServerName = "Your Server Name";
       crConnectionInfo.UserID = "Your User ID";
       crConnectionInfo.Password = "Your Password";   //Set the CrDatabase Object to the Report's Database
       crDatabase = crReportDocument.Database;   //Set the CrTables object to the Tables collection of the Report's dDtabase
       crTables = crDatabase.Tables;   //Loop through each Table object in the Tables collection and apply the logon info
       //specified ealier. Note this sample only has one table so the loop will only execute once
       foreach (Table crTable in crTables)
       {
        crTableLogOnInfo = crTable.LogOnInfo;
        crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
        crTable.ApplyLogOnInfo (crTableLogOnInfo);    // if you wish to change the schema name as well, you will need to set Location property as follows:
        // crTable.Location = "<new schema name>." + crTable.Name;
       }   //Set the ReportSource of the CrystalReportViewer to the strongly typed Report included in the project
       crystalReportViewer1.ReportSource = crReportDocument; 还有一点要注意:
    如果你用到了子报表,一定要处理://Go through each sections in the main report and identify the subreport by name
       crSections = crReportDocument.ReportDefinition.Sections;   foreach(Section crSection in crSections)
       {
        crReportObjects = crSection.ReportObjects;
        //loop through all the report objects to find all the subreports
        foreach(ReportObject crReportObject in crReportObjects)
        {
         if (crReportObject.Kind == ReportObjectKind.SubreportObject)
         {
          //you will need to typecast the reportobject to a subreport 
          //object once you find it
          crSubreportObject = (SubreportObject)crReportObject;      //open the subreport object
          crSubReportDoc = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName);
          //Once the correct subreport has been located pass it the 
          //appropriate dataset
          if(crSubReportDoc.Name == "FirstSub") 
          {
           //crSubReportDoc.Database.Tables[0].SetDataSource(ds);
           crSubReportDoc.SetDataSource(ds);
          }
         }
        }
       }
       crystalReportViewer1.ReportSource = crReportDocument;同样crSubReportDoc.SetDataSource(ds);改为:crSubReportDoc.SetDataSource(ds.Tables["tablename"]);
      

  2.   

    我的理解是这样的,不知道对不对,如果是推模式,那么一般建立一个DATASET,然后报表连接到这个dataset,在需要显示报表的时候,连接数据库并将查询到的数据填充到这个dataset。我的推模式下使用的代码是这样的,麻烦给看看,应该如何改
    page_Load中写下面的代码
    YabOA.Dataset1.SlinfoVwOfZbDataTable ds = new YabOA.Dataset1.SlinfoVwOfZbDataTable();
    string connectString = ConfigurationSettings.AppSettings["CONNECTSTRING"];
    SqlConnection MyConnection = new SqlConnection(connectString);
    MyConnection.Open();
    string sqlstring = "select xh,rq,sl from SlinfoVwOfZb"; SqlDataAdapter MyCommand = new SqlDataAdapter(sqlstring,MyConnection);

    MyCommand.Fill(ds);
                                YabOA.CrystalReport1 cr1 = new YabOA.CrystalReport1();      
    cr1.SetDataSource(ds);
                               //如果没有下面的这句,不报错,但自然也不会显示报表
    this.CustomerOrderCRViewer.ReportSource = cr1;


    MyConnection.Close();
      

  3.   

    更郁闷了。。同样的代码,我放到windowsApplication就可以显示出报表,但在web下就是不行。。如果是权限的问题,那么为什么我用pull模式的时候可以啊??????各位老大,帮帮俺把。
      

  4.   


    web 和 windows application 的 crystal report的模式是不同的。虽然控件看起来差不多。比如打印,windows application可以轻易解决。 而web就要复杂拉了
      

  5.   

    给段代码做参考  前两天刚做的  测试通过
    string strProvider = "Server=(local);User ID=sa;PWD=;DataBase=BOM";
    SqlConnection MyConn = new SqlConnection(strProvider);
    MyConn.Open();
    string strSel = "Select * from CountryC";
    SqlDataAdapter MyAdapter = new SqlDataAdapter(strSel,MyConn);
    DataSetPush ds = new DataSetPush();
    MyAdapter.Fill(ds,"CountryC");
    MyConn.Close();
    ReportDoc.Load(Server.MapPath("myCrystalReportPush.rpt"));
    ReportDoc.SetDataSource(ds);
    CrystalReportViewer1.ReportSource = ReportDoc;
    CrystalReportViewer1.DataBind();
      

  6.   

    楼上的,你的方法我用了,可还是说登陆错误。。要疯了啊。。这应该是水晶报表最基本的用法啊,我在windows应用程序下用,同样的操作方式,同样的代码,就没有问题,可在web下,就不行我怀疑是权限的问题,但我用pull方法的时候,已经通过了啊。。
      

  7.   

    报表我也不太懂,但我想想你可以试下去实例化数据集,也就是
    YabOA.Dataset1 ds=new YabOA.Dataset1();
    ....
    ...
    填充这个表看看,我第一次做的时候,就这样一次就成功了
    MyCommand.Fill(ds,"SlinfoVwOfZbDataTable");
    .......
      

  8.   

    我把代码改成下面的就搞定了,但不知道为什么
    //YabOA.Dataset1.SlinfoVwOfZbDataTable ds = new YabOA.Dataset1.SlinfoVwOfZbDataTable(); //这段不用了
    //改成
                                DataSet ds = new DataSet();
    string connectString = ConfigurationSettings.AppSettings["CONNECTSTRING"];
    SqlConnection MyConnection = new SqlConnection(connectString);
    MyConnection.Open();
    string sqlstring = "select xh,rq,sl from SlinfoVwOfZb"; SqlDataAdapter MyCommand = new SqlDataAdapter(sqlstring,MyConnection);

    MyCommand.Fill(ds,"SlinfoVwOfZb");
                                YabOA.CrystalReport1 cr1 = new YabOA.CrystalReport1();      
    cr1.SetDataSource(ds.Tables["SlinfoVwOfZb"]);
    this.CustomerOrderCRViewer.ReportSource = cr1;


    MyConnection.Close();
    那位高人给解释一下,我的报表中的字段是从YabOA.Dataset1.SlinfoVwOfZbDataTable的架构中获得,为什么我生成YabOA.Dataset1.SlinfoVwOfZbDataTable的实例,然后Fill填充,却不行,而生成一个DataSet却可以,我同样是把数据从数据库中取得,然后填充入DataSet中啊。。??
      

  9.   

    我一般用水晶报表的推模式,这样比较好控制结构.最好是按照你需要的表结构建立XSD文件作为你的数据源,然后新建DataSet,为这个DataSet建立和你的XSD文件一样的结构,这些最好都是手动建立比较好,然后按照我开始所说的,这样就不会有问题.为什么,我也不太清楚.
      

  10.   

    YabOA.Dataset1.SlinfoVwOfZbDataTable是数据集吗?这样看应该是数据集里的一个表啊,不应该当数据集用吧!!综合来看,要不就是你的数据集声明有问题,要不就是Dataset1里数据表之间的链接关系有问题!!
      

  11.   

    可是我用同样的操作方式,同样的代码,在windowsApplicatioin中却可以运行成功啊!我的Dataset1是一个数据集文件,slinfoVwOfzb是从数据库托进去的一个表结构。
      

  12.   

    DataSet1的创建如下:
    添加入项目-》数据集文件-》dataset.xsd,然后从资源管理器那里托进来了sql server中的一个表,就出现了slinfovwofzb。。这个是吗???
      

  13.   

    YabOA.Dataset1.SlinfoVwOfZbDataTable ds = new YabOA.Dataset1.SlinfoVwOfZbDataTable();
    中的YabOA代表什么呢,
      

  14.   

    我按照以下方法实现了,大家可以看看!                string connectString = ConfigurationManager.AppSettings["ConnectionString"];
            SqlConnection MyConn = new SqlConnection(connectString);
            MyConn.Open();
            string strSel = "Select UserName,UserPwd,Question from UserInfo";
            SqlDataAdapter MyAdapter = new SqlDataAdapter(strSel, MyConn);
            DataSet ds = new DataSet();
            MyAdapter.Fill(ds, "UserInfo");
            MyConn.Close();
            ReportDocument ReportDoc = new ReportDocument();
            ReportDoc.Load(Server.MapPath("\\Web\\Crystal") + @"\CrystalReport2.rpt");
            ReportDoc.SetDataSource(ds);
            CrystalReportViewer1.ReportSource = ReportDoc;
            CrystalReportViewer1.DataBind();