点击此处---> 群内免费提供SAP练习系统(在群公告中)加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)大家好,是否可以通过编程方式更改...
点击此处---> 群内免费提供SAP练习系统(在群公告中)加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)大家好,是否可以通过编程方式更改...
加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)
大家好,
是否可以通过编程方式更改报表 CommandTable 中的SQL文本?
出于研究目的,我创建了一个非常简单的报表,其中只有一个< strong> CommandTable 对象,其中包含以下sql:
从双精度中选择1111 AS N
然后我正尝试通过以下方式将此SQL替换为" SELECT 2222 AS N FROM dual":
CrystalDecisions.CrystalReports.Engine.ReportDocument doc = 新的CrystalDecisions.CrystalReports.Engine.ReportDocument(); doc.Load("С:\\ Temp \\ Test.rpt",CrystalDecisions.Shared.OpenReportMethod.OpenReportByTempCopy); CrystalDecisions.ReportAppServer.DataDefModel.PropertyBag newMainPropertyBag = 新的CrystalDecisions.ReportAppServer.DataDefModel.PropertyBag(); CrystalDecisions.ReportAppServer.DataDefModel.PropertyBag newInnerPropertyBag = 新的CrystalDecisions.ReportAppServer.DataDefModel.PropertyBag(); foreach(CrystalDecisions.Shared.NameValuePair2 pr2 在doc.Database.Tables [0] .LogOnInfo.ConnectionInfo.Attributes.Collection中) { 如果(pr2.Name.ToString()==" QE_LogonProperties") { foreach(CrystalDecisions.Shared.NameValuePair2 SubPair2在 (pr2.Value作为CrystalDecisions.Shared.DbConnectionAttributes).Collection) newInnerPropertyBag.Add(SubPair2.Name.ToString(),SubPair2.Value.ToString()); newMainPropertyBag.Add(" QE_LogonProperties",newInnerPropertyBag); } 其他 newMainPropertyBag.Add(pr2.Name.ToString(),pr2Value.ToString()); } CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfo newConnectionInfo = 新的CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfo(); newConnectionInfo.Attributes = newMainPropertyBag; newConnectionInfo.Kind = CrystalDecisions.ReportAppServer.DataDefModel.CrConnectionInfoKindEnum.crConnectionInfoKindCRQE; newConnectionInfo.UserName =" scott"; newConnectionInfo.Password =" xxxxx"; CrystalDecisions.ReportAppServer.DataDefModel.CommandTable NewCmdTable = 新的CrystalDecisions.ReportAppServer.DataDefModel.CommandTable(); CrystalDecisions.ReportAppServer.DataDefModel.CommandTable OldCmdTable = doc.ReportClientDocument.DatabaseController.Database.Tables [0] 作为CrystalDecisions.ReportAppServer.DataDefModel.CommandTable; NewCmdTable.ConnectionInfo = newConnectionInfo; NewCmdTable.Name = OldCmdTable.Name; NewCmdTable.QualifiedName = OldCmdTable.QualifiedName; NewCmdTable.Alias = OldCmdTable.Alias; NewCmdTable.CommandText =" SELECT 2222 AS N FROM dual"; doc.ReportClientDocument.DatabaseController.SetTableLocationEx(OldCmdTable,NewCmdTable); doc.SetDatabaseLogon(" scott"," xxxxx"); doc.VerifyDatabase(); doc.SaveAs("С:\\ Temp \\ DoneTest.rpt"); doc.Close();
很遗憾,此更改后,存储的报告无法完全正常运行,
因此,一旦我应用了 SetTableLocationEx 方法, ApplyLogOnInfo 和 ReplaceConnection 方法就什么都不做,也不会抛出任何异常。
< br>当我查看此报告的数据库连接参数时,
我发现"数据库Dll"参数从" crdb_oracle.dll"更改为" crdb_quary.dll"。
例如,在更改sql之前:
之后 SetTableLocationEx
为什么此数据库连接已更改?
有没有一种正确的方法来更改CommandTable中的SQL而无需更改数据库?
(1.9 kB)
其他信息:如果我使用" DataDefModel.Table"对象而不是" DataDefModel.CommonTable",则不会遇到任何问题。
一周热门 更多>