CodeKicks.com
Focus on Microsoft Technologies - Tutorials, Articles, Code Samples.

Tuesday, March 13, 2007

Passing parameters to Crystal Reports in .NET


Call this method in page load


private void LoadReport(string fileName)


{


try


{



rd = new ReportDocument();


rd.Load(Server.MapPath(@"CrystalReport\" + fileName),OpenReportMethod.OpenReportByTempCopy);


rd.SetDatabaseLogon(GenericFunctions.UID.ToLower(),GenericFunctions.PWD.ToLower(),GenericFunctions.SERVER.ToLower(),GenericFunctions.DATABASE.ToLower());


if(ViewState["Params"] != null)


{


AssignParamValues(rd);


}


CrystalReportViewer1.ReportSource = rd;


}


catch(Exception ex)


{


Response.Write(ex.Message);


}


}


 


private void AssignParamValues(ReportDocument rd)


{



string[] Params = ViewState["Params"].ToString().Split('$');


string[] Values = ViewState["Values"].ToString().Split('$');


for(int cntParams = 0 ; cntParams < Params.Length; cntParams++)


{


rd.SetParameterValue(Params[cntParams],Values[cntParams]);


}


}

Post a Comment