Iam trying to display the StartTime and EndTime on the header of the report at run time.
At design time I have the report pointing to diffrent server database Iam overriding the values at runtime. Iam able to fetch the records with the new server database name at runtime and everything is working fine except the Prameter fields (which are dragged and dropped at design time) are not being overridden by the new values at runt time.

Iam able to see new Server/ Database and the records but the header is not displaying the StartTime and EndTime at the runtime any help is appreciated
code is pasted below


Iam unable to find what mistake I am making thanks in advance


public ReportDocument PrepareReports(string reportFileName)
{
//string databaseOwner =
ConfigurationManager.AppSettings["DatabaseOwner"];

ReportDocument rptDocument = new ReportDocument();

rptDocument.Load(reportFileName);

SqlConnectionStringBuilder reportsConnectionString = new
SqlConnectionStringBuilder(ConfigurationManager.Co nnectionStrings["ReportsConnectionString"].ConnectionString);

ConnectionInfo crConnectionInfo = new ConnectionInfo();
crConnectionInfo.ServerName =
reportsConnectionString.DataSource;
crConnectionInfo.DatabaseName =
reportsConnectionString.InitialCatalog;
crConnectionInfo.UserID = reportsConnectionString.UserID;
crConnectionInfo.Password = reportsConnectionString.Password;

foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in
rptDocument.Database.Tables)
{
crTable.LogOnInfo.ConnectionInfo = crConnectionInfo;
crTable.ApplyLogOnInfo(crTable.LogOnInfo);
crTable.Location = crTable.Location;

}

foreach (CrystalDecisions.CrystalReports.Engine.Section
crSection in rptDocument.ReportDefinition.Sections)
{
foreach (CrystalDecisions.CrystalReports.Engine.ReportObje ct
crReportObject in crSection.ReportObjects)
{
if (crReportObject.Kind == ReportObjectKind.SubreportObject)
{
SubreportObject subReportObject =
(CrystalDecisions.CrystalReports.Engine.SubreportO bject)(crReportObject);
ReportDocument subReportDocument =
subReportObject.OpenSubreport(subReportObject.Subr eportName);
foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in
subReportDocument.Database.Tables)
{
crTable.LogOnInfo.ConnectionInfo = crConnectionInfo;
crTable.ApplyLogOnInfo(crTable.LogOnInfo);
}
}
}
}
return rptDocument;
}

/// <summary>
/// This Function Loops through the Reports for input parameters
/// right now there are 4 diffrent input parameters
/// StartTime, StopTime, SecurityGroupID and ReportItemID
/// </summary>
/// <param name="Rpt"></param>
/// <param name="RptViewerId"></param>
/// <param name="ReportItemId"></param>
/// <param name="StartTime"></param>
/// <param name="EndTime"></param>
public void GetParams(ReportDocument Rpt, CrystalReportViewer
RptViewerId, int ReportItemId, DateTime StartTime, DateTime EndTime, int
SecurityGroupId )
{
ParameterFields ParamFields = new ParameterFields();
ParameterDiscreteValue SpValue = new ParameterDiscreteValue();

string FieldName;
RptViewerId.ParameterFieldInfo.Clear(); //Clear all
ParameterFieldInfo from CrystalReportViewer to load fresh info

foreach (ParameterField ParamField in Rpt.ParameterFields)
{
FieldName = ParamField.Name.ToUpper();
switch (FieldName)
{
case "@STARTTIME":
SpValue.Value = StartTime;
ParamField.CurrentValues.Add(SpValue);
ParamFields.Add(ParamField);

break;
case "@STOPTIME":
SpValue.Value = EndTime;
ParamField.CurrentValues.Add(SpValue);
ParamFields.Add(ParamField);
break;
case "@SECURITYGROUPID":
SpValue.Value = SecurityGroupId;
ParamField.CurrentValues.Add(SpValue);
ParamFields.Add(ParamField);
break;
case "@REPORTITEMID":
SpValue.Value = ReportItemId;
ParamField.CurrentValues.Add(SpValue);
ParamFields.Add(ParamField);
break;

}
}

RptViewerId.ReportSource = Rpt; //Set Crystal ReportViewer's
ReportSource to ReportDocument
// RptViewerId.ParameterFieldInfo = ParamFields; //Set Crystal
RepotViewer's ParameterFieldInfo to ParameterFields
}