水晶报表数据库登录参数
本文关键字:参数 登录 数据库 报表 水晶 | 更新日期: 2023-09-27 17:50:40
你好,我有一个基于windows的c#应用程序,使用Crystal报表作为我的报表工具。我已经提供了所有的登录和数据库信息,但当我运行和部署它…它仍然要求数据库登录。
下面是我的代码
ReportDocument rpt = new ReportDocument();
TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
Tables CrTables;
rpt.Load("C:/Operation/Reports/po.rpt");
crConnectionInfo.ServerName = "192.4.4.4";
crConnectionInfo.DatabaseName = "Operations";
crConnectionInfo.UserID = "sa";
crConnectionInfo.Password = "xxxxxx";
ParameterFieldDefinitions crParameterFieldDefinitions;
ParameterFieldDefinition crParameterFieldDefinition;
ParameterValues crParameterValues = new ParameterValues();
ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();
crParameterDiscreteValue.Value = DbClass.PONumber;
crParameterFieldDefinitions = rpt.DataDefinition.ParameterFields;
crParameterFieldDefinition = crParameterFieldDefinitions["ParameterPO"];
crParameterValues = crParameterFieldDefinition.CurrentValues;
crParameterValues.Clear();
crParameterValues.Add(crParameterDiscreteValue);
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);
CrTables = rpt.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
crtableLogoninfo = CrTable.LogOnInfo;
crtableLogoninfo.ConnectionInfo = crConnectionInfo;
CrTable.ApplyLogOnInfo(crtableLogoninfo);
}
crpt.Refresh();
crpt.ReportSource = rpt;
我头痛的问题是…如果有人知道这件事,请给我一个主意。
谢谢!
先打开连接。使用:
SqlConnection myConnection = new SqlConnection("xxx");
myConnection.Open();
// Your Code
myConnection.Close();