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. 

img1

img2

img3

 

Can anyone please help me?


Asked by:- SalmanZahir
0
: 203 At:- 5/14/2018 5:12:20 AM
asp.net mvc crystal report






1 Answers
profileImage Answered by:- vikas_jk

It looks like you are following the answer provided here https://qawithexperts.com/questions/138/how-to-show-only-a-single-record-with-crystal-report-in-aspn

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;
                CrTable.ApplyLogOnInfo(crtableLogoninfo);
            }

            crystalReportViewer1.ReportSource = cryRpt;
            crystalReportViewer1.Refresh(); 

http://csharp.net-informations.com/crystal-reports/csharp-crystal-reports-dynamic-login.htm

There is another complete tutorial on this https://www.aspdotnet-suresh.com/2012/01/crystal-reports-sample-in-aspnet.html

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

https://community.ivanti.com/thread/31347

Also, as per the answer here https://www.experts-exchange.com/questions/28520468/Database-logon-failed-when-exporting-Crystal-Report-to-PDF.html you need to have SQL native client installed.

2
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
Or
Register directly by posting answer/details

Full Name *

Email *




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