How to show Crystal report for two tables related by foreign key?

I have two tables tbl_employee and tbl_department. I want to show a crystal report for employee information where department name should be there. When I am trying to show the report only for the employee table it is working fine but when I am joining these two tables with key in crystal report design, logon error exception is shown. 





Can anyone please help me?

Asked by:- SalmanZahir
: 3261 At:- 5/14/2018 5:12:20 AM mvc crystal report

1 Answers
profileImage Answered by:- vikas_jk

It looks like you are following the answer provided here

Which looks ok to me & I don't think it is related to multiple table's data fetch but according to error mentioned by you in the image "Database Logon Failed" you need to provide database details while generating reports also, here is the example about how to generate reports with dynamic logon

            ReportDocument cryRpt = new ReportDocument();
            TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
            TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
            ConnectionInfo crConnectionInfo = new ConnectionInfo();
            Tables CrTables ;

            cryRpt.Load("PUT CRYSTAL REPORT PATH HERE\CrystalReport1.rpt");

            crConnectionInfo.ServerName = "YOUR SERVER NAME";
            crConnectionInfo.DatabaseName = "YOUR DATABASE NAME";
            crConnectionInfo.UserID = "YOUR DATABASE USERNAME";
            crConnectionInfo.Password = "YOUR DATABASE PASSWORD";

            CrTables = cryRpt.Database.Tables ;
            foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
                crtableLogoninfo = CrTable.LogOnInfo;
                crtableLogoninfo.ConnectionInfo = crConnectionInfo;

            crystalReportViewer1.ReportSource = cryRpt;

There is another complete tutorial on this

If that doesn't help you, check similar issue's

Also, as per the answer here you need to have SQL native client installed.

At:- 5/14/2018 2:45:02 PM Updated at:- 5/14/2018 2:45:39 PM
Solved the problem by using datasets. Reports are so much easier now. Thanks :D 0
By : SalmanZahir - at :- 5/24/2018 5:25:08 AM
Thanks for commenting and letting us know 0
By : vikas_jk - at :- 5/24/2018 6:58:48 AM

Login/Register to answer
Register directly by posting answer/details

Full Name *

Email *

By posting your answer you agree on privacy policy & terms of use