hi guys i wan to make dyanmic crystal report according to values which i checked from check box
thats all i did

1. I made data set having data table name "Customer"
2 i put four columm id,name
,age ,sex
3. then i made crystal report and drag those columm in crystal report
4 thn i drag crystal report viwer
5 thn i write tht code at button click

protected void Button1_Click(object sender, EventArgs e)
    {
     
        ////CrystalReport1 objRpt;
        ////objRpt = new CrystalReport1();
        ReportDocument report = new ReportDocument();
        string reportPath = Server.MapPath("CrystalReport1.rpt");

        report.Load(reportPath); 


        string connString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
            "Data Source=D:\\mayank/db2.mdb";

        //Get Select query String and add parameters to the 
        //Crystal report.
        string query = CreateSelectQueryAndParameters();
        
        //if there is no item select, then exit from the method.
        if (!query.Contains("Column"))
        {
            Response.Write("No selection to display!");
            return;
        }

        try
        {
            OleDbConnection Conn = new OleDbConnection(connString);

            OleDbDataAdapter adepter =
            new OleDbDataAdapter(query, connString);
            DataSet1 Ds = new DataSet1();

            adepter.Fill(Ds, "Customer");
            Response.Write(Ds);
            report.SetDataSource(Ds);
            crystalReportViewer1.ReportSource = report;

        }
        catch (OleDbException oleEx)
        {
          //  MessageBox.Show(oleEx.Message);
        }
        catch (Exception Ex)
        {
            //MessageBox.Show(Ex.Message);
        }

    }
    private string CreateSelectQueryAndParameters()
    {
        ReportDocument reportDocument;
        ParameterFields paramFields;

        ParameterField paramField;
        ParameterDiscreteValue paramDiscreteValue;

        reportDocument = new ReportDocument();
        paramFields = new ParameterFields();

        string query = "SELECT ";
        int columnNo = 0;

        if (CheckBox1.Checked)
        {
            columnNo++;
            query = query.Insert(query.Length, "Code as Column" +
            columnNo.ToString());

            paramField = new ParameterField();
            paramField.Name = "col" + columnNo.ToString();
            paramDiscreteValue = new ParameterDiscreteValue();
            paramDiscreteValue.Value = "Customer Code";
            paramField.CurrentValues.Add(paramDiscreteValue);
            //Add the paramField to paramFields
            paramFields.Add(paramField);
        }
        if (CheckBox2.Checked)
        {
            columnNo++;
            if (query.Contains("Column"))
            {
                query = query.Insert(query.Length, ", ");
            }
            query = query.Insert(query.Length, "FirstName as Column" +
            columnNo.ToString());

            paramField = new ParameterField();
            paramField.Name = "col" + columnNo.ToString();
            paramDiscreteValue = new ParameterDiscreteValue();
            paramDiscreteValue.Value = "First Name";
            paramField.CurrentValues.Add(paramDiscreteValue);
            //Add the paramField to paramFields
            paramFields.Add(paramField);
        }
        if (CheckBox3.Checked)
        {
            columnNo++; //To determine Column number
            if (query.Contains("Column"))
            {
                query = query.Insert(query.Length, ", ");
            }
            query = query.Insert(query.Length, "LastName as Column" +
            columnNo.ToString());

            paramField = new ParameterField();
            paramField.Name = "col" + columnNo.ToString();
            paramDiscreteValue = new ParameterDiscreteValue();
            paramDiscreteValue.Value = "Last Name";
            paramField.CurrentValues.Add(paramDiscreteValue);
            //Add the paramField to paramFields
            paramFields.Add(paramField);
        }
        if (CheckBox4.Checked)
        {
            columnNo++;
            if (query.Contains("Column"))
            {
                query = query.Insert(query.Length, ", ");
            }
            query = query.Insert(query.Length, "Address as Column" +
            columnNo.ToString());

            paramField = new ParameterField();
            paramField.Name = "col" + columnNo.ToString();
            paramDiscreteValue = new ParameterDiscreteValue();
            paramDiscreteValue.Value = "Address";
            paramField.CurrentValues.Add(paramDiscreteValue);
            //Add the paramField to paramFields
            paramFields.Add(paramField);
        }
       

        //if there is any remaining parameter, assign empty value for that 
        //parameter.
        for (int i = columnNo; i < 5; i++)
        {
            columnNo++;
            paramField = new ParameterField();
            paramField.Name = "col" + columnNo.ToString();
            paramDiscreteValue = new ParameterDiscreteValue();
            paramDiscreteValue.Value = "";
            paramField.CurrentValues.Add(paramDiscreteValue);
            //Add the paramField to paramFields
            paramFields.Add(paramField);
        }

        crystalReportViewer1.ParameterFieldInfo = paramFields;

        query += " FROM Customer";
      
        return query;
    }

it showing no error but crstal report is generating

plz tel me the solution its very urgent

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.