Cela fait maintenant 4 jours que je me bats avec ça. J'ai un rapport de cristal très très simple (je l'utilise juste pour une preuve de concept). Le rapport est lié à une base de données et j'affiche un seul champ d'une table dans la base de données. Pas de sous-rapports.Il a été créé avec Crystal Reports 2008. Je dois afficher ce rapport dans mon application web .Net MVC mais je dois pouvoir pour changer les informations de connexion à la base de données depuis cette application. sera utilisé contre différentes bases de données avec une structure de table identique. J'ai donc créé un formulaire Web standard et j'ai déplacé un CrystalReportViewer et CrystalReportSource.Crystal Rapports et données Liaison à l'exécution
Ceci est mon code:
protected void Page_Load(object sender, EventArgs e)
{
this.CrystalReportSource1.EnableCaching = false;
this.CrystalReportSource1.ReportDocument.Load(@"C:\ReportName.rpt");
//1) I get the data connection variables from my app - this part works well
and is irrelevant in this case.
//2) Once I have the data I need to apply it to the connection of the report
ConnectionInfo crConnection = new ConnectionInfo();
crConnection.UserID = userID;
crConnection.ServerName = datasource;
crConnection.DatabaseName = "";
crConnection.Password = password;
AssignConnectionInfo(CrystalReportSource1.ReportDocument,crConnection);
CrystalReportSource1.ReportDocument.DataSourceConnections[0].SetConnection
(crConnection.ServerName, crConnection.DatabaseName, false);
CrystalReportSource1.ReportDocument.SetDatabaseLogon(crConnection.UserID,
crConnection.Password, crConnection.ServerName, crConnection.DatabaseName);
CrystalReportViewer1.ReportSource = CrystalReportSource1.ReportDocument;
CrystalReportViewer1.RefreshReport();
}//close the page load function
Ceci est la AssignConnectionInfo Fonction:
private void AssignConnectionInfo(ReportDocument document,ConnectionInfo crConnection)
{
foreach (CrystalDecisions.CrystalReports.Engine.Table table in document.Database.Tables)
{
TableLogOnInfo logOnInfo = table.LogOnInfo;
if (logOnInfo != null)
{
table.ApplyLogOnInfo(table.LogOnInfo);
table.LogOnInfo.TableName = table.Name;
table.LogOnInfo.ConnectionInfo.UserID = crConnection.UserID;
table.LogOnInfo.ConnectionInfo.Password = crConnection.Password;
table.LogOnInfo.ConnectionInfo.DatabaseName = crConnection.DatabaseName;
table.LogOnInfo.ConnectionInfo.ServerName = crConnection.ServerName;
CrystalReportViewer1.LogOnInfo.Add(table.LogOnInfo);
}
}
}
donc ce qui se passe est que la page se charge et la bannière cristal, barre d'outils affiche, mais le champ databound que je avoir dans mon rapport est vide. Ne vois-tu rien de mal?
Merci très beaucoup à l'avance
Susan
Merci beaucoup. En fait, ce qui fait la différence est le transfert du code de la fonction Load vers la fonction Init de l'objet Reportviewer. Ça fonctionne maintenant. Merci encore pour toute l'aide. – suzi167