Here I am going to show you how to dynamically login in Crystal Reports. Sometimes developer faces the issue that he has to provide server name and etc this code will help you to remove those exceptions in applications.
- TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
- TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
- Tables CrTables;
-
- ConnectionInfo Cr = new ConnectionInfo();
- Cr.ServerName = "";
- Cr.DatabaseName = "";
- Cr.UserID = "";
- Cr.Password = "";
- CrTables = Ip.Database.Tables;
-
- foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
- {
- crtableLogoninfo = CrTable.LogOnInfo;
- crtableLogoninfo.ConnectionInfo = Cr;
- CrTable.ApplyLogOnInfo(crtableLogoninfo);
- }
- crystalReportViewer1.ReportSource = Ip;
In this code I have created a crystal report and created its object IP and used that in the report source.