How to pass Login details to CrystalReport in C#.net
Dynamically passing DataBase Login details to Crystal Reports in C#.net.
Add references :
" using CrystalDecisions.CrystalReports.Engine"
"using CrystalDecisions.Shared"
Passing Databse login details:
{
ReportDocument rdc1 = new ReportDocument();
TableLogOnInfos tli = new TableLogOnInfos();
TableLogOnInfo tloi = new TableLogOnInfo();
ConnectionInfo cinf = new ConnectionInfo();
Tables crtables;
//here my report is saved in Debug folder of my project.
rdc1.Load("test.rpt");
cinf.ServerName = "system1";
cinf.DatabaseName = "testdb";
cinf.UserID = "uid";
cinf.Password = "pwd";
crtables = rdc1.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table ctable in crtables)
{
tloi = ctable.LogOnInfo;
tloi.ConnectionInfo = cinf;
ctable.ApplyLogOnInfo(tloi);
}
//"report" is a form which contains CrystalReportViewer on it.
report rt = new report();
rt.crystalReportViewer1.ReportSource = rdc1;
//if there is any parameters to send to report then send those parameters by using property "SelectionFormula".
syntax: rt.crystalReportViewer1.SelectionFormula = "{empl.pid}=" + textBox.Text;
rt.Show();
//here empl.pid is the column name to send to crystalreport //column name must in {} only i.e{empl.pid}.
}
Dynamically passing DataBase Login details to Crystal Reports in C#.net.
Add references :
" using CrystalDecisions.CrystalReports.Engine"
"using CrystalDecisions.Shared"
Passing Databse login details:
{
ReportDocument rdc1 = new ReportDocument();
TableLogOnInfos tli = new TableLogOnInfos();
TableLogOnInfo tloi = new TableLogOnInfo();
ConnectionInfo cinf = new ConnectionInfo();
Tables crtables;
//here my report is saved in Debug folder of my project.
rdc1.Load("test.rpt");
cinf.ServerName = "system1";
cinf.DatabaseName = "testdb";
cinf.UserID = "uid";
cinf.Password = "pwd";
crtables = rdc1.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table ctable in crtables)
{
tloi = ctable.LogOnInfo;
tloi.ConnectionInfo = cinf;
ctable.ApplyLogOnInfo(tloi);
}
//"report" is a form which contains CrystalReportViewer on it.
report rt = new report();
rt.crystalReportViewer1.ReportSource = rdc1;
//if there is any parameters to send to report then send those parameters by using property "SelectionFormula".
syntax: rt.crystalReportViewer1.SelectionFormula = "{empl.pid}=" + textBox.Text;
rt.Show();
//here empl.pid is the column name to send to crystalreport //column name must in {} only i.e{empl.pid}.
}
No comments:
Post a Comment