Click here to Skip to main content
15,917,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Good Afternoon Developers,
This is my function to generate the crystal Report,This will take the Report Name and ReportQuery as a input parameter and will generate a dataset , With this dataset how can i design my Report??Because this is Generated at the runtime , How can i access that to generate my ReportDesign??

Any help is appreciable....!


public void fnLoadDataToReport(string rptName, string rptQuery)
{
    try
    {
        DataSet myDS=new DataSet();
//      crReportDocument.Load(Server.MapPath("Reports\" & RptName), OpenReportMethod.OpenReportByTempCopy);
        crReportDocument.Load(Server.MapPath("Reports\\" + rptName ));
        SqlConnection myConnection=new SqlConnection(ConfigurationManager.ConnectionStrings["mycon"].ConnectionString);
        SqlCommand myCommand=new SqlCommand(rptQuery,myConnection);
        SqlDataAdapter MyDA=new SqlDataAdapter(myCommand);
        MyDA.Fill(myDS,"ReportTable");
        crReportDocument.SetDataSource(myDS);
        crvReportGeneration.ReportSource=crReportDocument;
        crvReportGeneration.ShowFirstPage();
    }
    catch(Exception ex)
    {
        Response.Write(ex.Message);
    }
}
Posted

1 solution

If you're dataset is fixed (meaning same query except for where clause) it might be easier to create a report that takes in one or more parameters and let the report do the rest.

eg. the query is :
SQL
select emp_id, emp_name, emp_grade from employees where emp_category = :p0;


you create the report as you wish and send the :p0 parameter to the report through .Net. The report handles the rest.

hope this helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900