请帮我解决Crystal报告有多个参数传递&动态更改数据库信息。我的代码如下:
ParameterFields paramFields = new ParameterFields();
ReportDocument reportDocument = new ReportDocument();
reportDocument.Load(Server.MapPath(ReportName + ".rpt"));
ParameterDiscreteValue crParameterDiscreteValue= new ParameterDiscreteValue();
ParameterFieldDefinitions crParameterFieldDefinitions ;
ParameterFieldDefinition crParameterFieldLocation ;
ParameterValues crParameterValues = new ParameterValues();
crParameterFieldDefinitions= reportDocument.DataDefinition.ParameterFields;
// 1stParameter Satrt
crParameterFieldLocation= crParameterFieldDefinitions["@userid"];
crParameterValues= crParameterFieldLocation.CurrentValues;
crParameterDiscreteValue= new CrystalDecisions.Shared.ParameterDiscreteValue();
crParameterDiscreteValue.Value=Convert.ToInt64(ViewState["userid"]);
crParameterValues.Add(crParameterDiscreteValue);
crParameterFieldLocation.ApplyCurrentValues(crParameterValues);
//1st Parameter End
// 2nd Parameter Satrt
crParameterFieldLocation= crParameterFieldDefinitions["@Reportname"];
crParameterValues= crParameterFieldLocation.CurrentValues;
crParameterDiscreteValue= new CrystalDecisions.Shared.ParameterDiscreteValue();
crParameterDiscreteValue.Value=ReportName;
crParameterValues.Add(crParameterDiscreteValue);
crParameterFieldLocation.ApplyCurrentValues(crParameterValues);
//2nd Parameter End
// 3rd Parameter Satrt
crParameterFieldLocation= crParameterFieldDefinitions["@SessionId"];
crParameterValues= crParameterFieldLocation.CurrentValues;
crParameterDiscreteValue= new CrystalDecisions.Shared.ParameterDiscreteValue();
crParameterDiscreteValue.Value=Session.SessionID.ToString();
crParameterValues.Add(crParameterDiscreteValue);
crParameterFieldLocation.ApplyCurrentValues(crParameterValues);
//3rd Parameter End
CrystalReportViewer1.ReportSource = reportDocument;
CrystalReportViewer1.EnableDatabaseLogonPrompt = false;
ConnectionInfo connectionInfo = new ConnectionInfo();
connectionInfo.ServerName = "192.168.0.245";
connectionInfo.DatabaseName = "Databasename";
connectionInfo.UserID = "sa";
connectionInfo.Password = "Password1";
TableLogOnInfo tableLogOnInfo = new TableLogOnInfo();
tableLogOnInfo.ConnectionInfo= connectionInfo;
foreach (CrystalDecisions.CrystalReports.Engine.Table table in reportDocument.Database.Tables)
{
table.ApplyLogOnInfo(tableLogOnInfo);
}
现在说“无法打开行集”。当我使用确切的参数值手动运行存储过程时,它会显示结果。所以存储过程返回值。请帮帮我。在Crystal报表的设计过程中,数据库服务器信息与传递的信息不同。
答案 0 :(得分:1)
不是在服务器名称中提供IP,而是在服务器系统中创建DSN(如果数据库是系统所有,在同一系统中创建DSN)并将DSN名称作为服务器名称,并提供相应的数据库详细信息DSN。
它会工作,我实施和测试。
答案 1 :(得分:0)
在您的系统中创建DSN,然后尝试使用此代码,
ConnectionInfo connectionInfo1 = new ConnectionInfo();
connectionInfo1.ServerName = "Your system dsn name";
connectionInfo1.DatabaseName = "database name";
connectionInfo1.UserID = "username";
connectionInfo1.Password = "secure password";