解決水晶報表出現登陸框的問題

你最好還是用sql連接,因爲oledb和sql的連接信息不是一樣的.

如果你用的是水晶報表的推模式,一般不用設置登陸信息,但是要這樣寫: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"]);

http://dev.csdn.net/develop/article/76/76324.shtm

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章