在使用水晶报表的时候发生了这样的问题。 奇怪的出现了数据库登陆对话框。请问这是为什么呢?
我的程序是这样写的:private void Form1_Load(object sender, System.EventArgs e)
{
this.sqlDataAdapter1.Fill(this.dataSet11, "Orders");
this.dvView = new DataView();
this.dvView.Table = this.dataSet11.Tables["Orders"];

ReportDocument obj = new ReportDocument();
obj.Load("E:\\vs\\WindowsApplication1\\order1.rpt");
obj.SetDataSource(this.dvView);//如果我给这个函数this.dataSet11就不会出现上面的对话框
this.crystalReportViewer1.ReportSource = obj;
}请问怎么解决这个问题呢?是不是SetDataSource()就只能传递数据级呢?我记得我以前还传递过DataTable呢。可是这次是怎么了?另外把报表导出到EXCL之后日期字段都变成了#######。怎么回事呢?

解决方案 »

  1.   

    http://forum.justdn.org/index.php?s=ceeb5ba0357f4193ecdbb5cf1ac2ef74&showtopic=14318
      

  2.   

    我也遇到同样的问题,
    如果你用的是水晶报表的推模式,一般不用设置登陆信息,但是要这样写: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"]);我只遇到这样的问题,也是这样解决的。