1

I have c# report PDF export project based on a dataTable I have manually created. I am using the following code to try and set the datasource and have tried many different variations but cannot get the information from my database to show up properly in my report exported as PDF. And saving as hard disk of my computer.

But when running the folllowing code, I can't see any PDF being exported. The exception is below

CrystalDecisions.CrystalReports.Engine.LogOnException: Database logon failedSystem.Runtime.InteropServices.COMException: Database logon failed.

I have set two data source , contract , contract members in main report sub report for contract members

one contract can have many contract members.

It occurs at the last line

Any help is greatly appreciated. The below is my code

   string result;
            ContractReport report = new ContractReport();
            ContractDTO source = new ContractDTO();            
            report.Load(Server.MapPath("~/ContractReport.rpt"));
            source.Id = 1;
            source.Code = "ABC";
            source.Title = "LondonEast";          
            source.Member = new List<ContractMembersDTO>();
            source.Member.Add(new ContractMembersDTO() { Id = 1, ContractId = 1, StaffNameEng = "ABC", Position = "Project Manager" });
            source.Member.Add(new ContractMembersDTO() { Id = 2, ContractId = 1, StaffNameEng = "DEF", Position = "Project QS" });
            source.Member.Add(new ContractMembersDTO() { Id = 3, ContractId = 1, StaffNameEng = "GHI", Position = "Site Manager" });         
            report.SetDataSource(new[] { source });
            if (reportType.Equals("PDF"))
            {
                try
                {
                    MemoryStream oStream;
                    oStream = (MemoryStream)report.ExportToStream(ExportFormatType.PortableDocFormat);
4

1 に答える 1

1

レポートに単一のテーブルがある場合、構文は機能するはずです...

report.SetDataSource(myCustomSource);

メインレポートに複数のテーブルがある場合は、次を使用してみてください。

report.Database.Tables["DATASOURCE_TABLE_1"].SetDataSource(myCustomSource);
report.Database.Tables["DATASOURCE_TABLE_2"].SetDataSource(myOtherSource);

サブレポートがある場合は、それらも個別に設定する必要があります。

report.Subreports[0].SetDataSource(mySubreportDatasource);

または

report.Subreports[0].Database.Tables[0].SetDataSource(mySubreportDatasource1);
report.Subreports[1].Database.Tables[0].SetDataSource(mySubreportDatasource2);
于 2013-03-11T05:07:27.627 に答える