C#Crystal Reports动态登录参数 [英] C# Crystal Reports Dynamic Logon parameters
本文介绍了C#Crystal Reports动态登录参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
每次都要求我输入登录然后登录失败?
every time ask me to enter login and then login failed?
private void button1_Click(object sender, EventArgs e)
{
ReportDocument cryRpt = new ReportDocument();
TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
Tables CrTables ;
cryRpt.Load("F:\\final_library\\final_library\\allemp_rep.rpt");
crConnectionInfo.ServerName = "192.168.1.3";
crConnectionInfo.DatabaseName = "f_library";
crConnectionInfo.UserID = "sa";
crConnectionInfo.Password = "123456";
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();
}
推荐答案
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
public ReportDocument ConnectionInfo(ReportDocument rpt)
{
ReportDocument crSubreportDocument;
string[] strConnection = ConfigurationManager.ConnectionStrings[("AppConn")].ConnectionString.Split(new char[] { ';' });
Database oCRDb = rpt.Database;
Tables oCRTables = oCRDb.Tables;
CrystalDecisions.CrystalReports.Engine.Table oCRTable = default(CrystalDecisions.CrystalReports.Engine.Table);
TableLogOnInfo oCRTableLogonInfo = default(CrystalDecisions.Shared.TableLogOnInfo);
ConnectionInfo oCRConnectionInfo = new CrystalDecisions.Shared.ConnectionInfo();
oCRConnectionInfo.ServerName = strConnection[0].Split(new char[] { '=' }).GetValue(1).ToString();
oCRConnectionInfo.Password = strConnection[2].Split(new char[] { '=' }).GetValue(1).ToString();
oCRConnectionInfo.UserID = strConnection[1].Split(new char[] { '=' }).GetValue(1).ToString();
for (int i = 0; i < oCRTables.Count; i++)
{
oCRTable = oCRTables[i];
oCRTableLogonInfo = oCRTable.LogOnInfo;
oCRTableLogonInfo.ConnectionInfo = oCRConnectionInfo;
oCRTable.ApplyLogOnInfo(oCRTableLogonInfo);
if (oCRTable.TestConnectivity())
//' If there is a "." in the location then remove the
// ' beginning of the fully qualified location.
//' Example "dbo.northwind.customers" would become
//' "customers".
oCRTable.Location = oCRTable.Location.Substring(oCRTable.Location.LastIndexOf(".") + 1);
}
for (int i = 0; i < rpt.Subreports.Count; i++)
{
{
// crSubreportObject = (SubreportObject);
crSubreportDocument = rpt.OpenSubreport(rpt.Subreports[i].Name);
oCRDb = crSubreportDocument.Database;
oCRTables = oCRDb.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table aTable in oCRTables)
{
oCRTableLogonInfo = aTable.LogOnInfo;
oCRTableLogonInfo.ConnectionInfo = oCRConnectionInfo;
aTable.ApplyLogOnInfo(oCRTableLogonInfo);
if (aTable.TestConnectivity())
//' If there is a "." in the location then remove the
// ' beginning of the fully qualified location.
//' Example "dbo.northwind.customers" would become
//' "customers".
aTable.Location = aTable.Location.Substring(aTable.Location.LastIndexOf(".") + 1);
}
}
}
// }
rpt.Refresh();
return rpt;
}
这篇关于C#Crystal Reports动态登录参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文