Saturday 13 April 2013

Dynamically Login in Crystal Report

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 = "";//here you should provide your Server Name
Cr.DatabaseName = "";//here you should provide your Database Name
Cr.UserID = "";//here you should provide your User Name
Cr.Password = "";//here you should provide your 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.