Skip to Content
0
Former Member
Nov 20, 2013 at 07:10 AM

How to add the parameters in the Command Table object programmatically in C#

122 Views

Hi to all,

This is Mahesh, I am trying to create the crystal report .rpt file dynamically using code behind code in C#,

I can create the command table object using DatabaseController, but I need to pass the parameter in that command table.

Below is my code, I got the error like "Failed to retrieve the results", I had tried a lot, so can anyone tell me how to add the parameters in the Command Table object programmatically in C#

I hope will get the solution for this issue from this forum.

public void AddDatabaseTable(ref CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument iscdReportObject, SqlConnectionStringBuilder ConnectionString, string TableName)

{

PropertyBag LogOnDetails = default(PropertyBag);

PropertyBag QELogonProp = default(PropertyBag);

ConnectionInfo connInfo = default(ConnectionInfo);

CommandTable cmdTable = new CommandTable();

LogOnDetails = new PropertyBag();

QELogonProp = new PropertyBag();

QELogonProp.EnsureCapacity(4);

QELogonProp["Data Source"] = ConnectionString.DataSource;

QELogonProp["Initial Catalog"] = ConnectionString.InitialCatalog;

QELogonProp["Provider"] = "SQLOLEDB";

LogOnDetails.EnsureCapacity(6);

LogOnDetails["Database DLL"] = "crdb_ado.dll";

LogOnDetails["QE_DatabaseType"] = "OLE DB (ADO)";

LogOnDetails["QE_LogonProperties"] = QELogonProp;

LogOnDetails["QE_ServerDescription"] = "SQLOLEDB";

LogOnDetails["QE_SQLDB"] = "True";

connInfo = new ConnectionInfo();

connInfo.Attributes = LogOnDetails;

connInfo.UserName = ConnectionString.UserID;

connInfo.Password = ConnectionString.Password;

connInfo.Kind = CrConnectionInfoKindEnum.crConnectionInfoKindCRQE;

string sqlQueryString = "select GetIDName({?Parameter}) as IDName, ID from TableResults";

ISCRField iscrParameter = iscdReportObject.DataDefinition.ParameterFields.FindField("Parameter", CrFieldDisplayNameTypeEnum.crFieldDisplayNameName, CeLocale.ceLocaleUserDefault);

cmdTable.ConnectionInfo = connInfo;

cmdTable.CommandText = sqlQueryString;

cmdTable.Parameters.Add(iscrParameter);

cmdTable.Name =TableName;

cmdTable.Alias =TableName;

iscdReportObject.DatabaseController.AddTable(cmdTable);

}