471,071 Members | 4,765 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,071 software developers and data experts.

dyanmic crystal report

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

Expand|Select|Wrap|Line Numbers
  1. protected void Button1_Click(object sender, EventArgs e)
  2.     {
  3.  
  4.         ////CrystalReport1 objRpt;
  5.         ////objRpt = new CrystalReport1();
  6.         ReportDocument report = new ReportDocument();
  7.         string reportPath = Server.MapPath("CrystalReport1.rpt");
  8.  
  9.         report.Load(reportPath); 
  10.  
  11.  
  12.         string connString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
  13.             "Data Source=D:\\mayank/db2.mdb";
  14.  
  15.         //Get Select query String and add parameters to the 
  16.         //Crystal report.
  17.         string query = CreateSelectQueryAndParameters();
  18.  
  19.         //if there is no item select, then exit from the method.
  20.         if (!query.Contains("Column"))
  21.         {
  22.             Response.Write("No selection to display!");
  23.             return;
  24.         }
  25.  
  26.         try
  27.         {
  28.             OleDbConnection Conn = new OleDbConnection(connString);
  29.  
  30.             OleDbDataAdapter adepter =
  31.             new OleDbDataAdapter(query, connString);
  32.             DataSet1 Ds = new DataSet1();
  33.  
  34.             adepter.Fill(Ds, "Customer");
  35.             Response.Write(Ds);
  36.             report.SetDataSource(Ds);
  37.             crystalReportViewer1.ReportSource = report;
  38.  
  39.         }
  40.         catch (OleDbException oleEx)
  41.         {
  42.           //  MessageBox.Show(oleEx.Message);
  43.         }
  44.         catch (Exception Ex)
  45.         {
  46.             //MessageBox.Show(Ex.Message);
  47.         }
  48.  
  49.     }
  50.     private string CreateSelectQueryAndParameters()
  51.     {
  52.         ReportDocument reportDocument;
  53.         ParameterFields paramFields;
  54.  
  55.         ParameterField paramField;
  56.         ParameterDiscreteValue paramDiscreteValue;
  57.  
  58.         reportDocument = new ReportDocument();
  59.         paramFields = new ParameterFields();
  60.  
  61.         string query = "SELECT ";
  62.         int columnNo = 0;
  63.  
  64.         if (CheckBox1.Checked)
  65.         {
  66.             columnNo++;
  67.             query = query.Insert(query.Length, "Code as Column" +
  68.             columnNo.ToString());
  69.  
  70.             paramField = new ParameterField();
  71.             paramField.Name = "col" + columnNo.ToString();
  72.             paramDiscreteValue = new ParameterDiscreteValue();
  73.             paramDiscreteValue.Value = "Customer Code";
  74.             paramField.CurrentValues.Add(paramDiscreteValue);
  75.             //Add the paramField to paramFields
  76.             paramFields.Add(paramField);
  77.         }
  78.         if (CheckBox2.Checked)
  79.         {
  80.             columnNo++;
  81.             if (query.Contains("Column"))
  82.             {
  83.                 query = query.Insert(query.Length, ", ");
  84.             }
  85.             query = query.Insert(query.Length, "FirstName as Column" +
  86.             columnNo.ToString());
  87.  
  88.             paramField = new ParameterField();
  89.             paramField.Name = "col" + columnNo.ToString();
  90.             paramDiscreteValue = new ParameterDiscreteValue();
  91.             paramDiscreteValue.Value = "First Name";
  92.             paramField.CurrentValues.Add(paramDiscreteValue);
  93.             //Add the paramField to paramFields
  94.             paramFields.Add(paramField);
  95.         }
  96.         if (CheckBox3.Checked)
  97.         {
  98.             columnNo++; //To determine Column number
  99.             if (query.Contains("Column"))
  100.             {
  101.                 query = query.Insert(query.Length, ", ");
  102.             }
  103.             query = query.Insert(query.Length, "LastName as Column" +
  104.             columnNo.ToString());
  105.  
  106.             paramField = new ParameterField();
  107.             paramField.Name = "col" + columnNo.ToString();
  108.             paramDiscreteValue = new ParameterDiscreteValue();
  109.             paramDiscreteValue.Value = "Last Name";
  110.             paramField.CurrentValues.Add(paramDiscreteValue);
  111.             //Add the paramField to paramFields
  112.             paramFields.Add(paramField);
  113.         }
  114.         if (CheckBox4.Checked)
  115.         {
  116.             columnNo++;
  117.             if (query.Contains("Column"))
  118.             {
  119.                 query = query.Insert(query.Length, ", ");
  120.             }
  121.             query = query.Insert(query.Length, "Address as Column" +
  122.             columnNo.ToString());
  123.  
  124.             paramField = new ParameterField();
  125.             paramField.Name = "col" + columnNo.ToString();
  126.             paramDiscreteValue = new ParameterDiscreteValue();
  127.             paramDiscreteValue.Value = "Address";
  128.             paramField.CurrentValues.Add(paramDiscreteValue);
  129.             //Add the paramField to paramFields
  130.             paramFields.Add(paramField);
  131.         }
  132.  
  133.  
  134.         //if there is any remaining parameter, assign empty value for that 
  135.         //parameter.
  136.         for (int i = columnNo; i < 5; i++)
  137.         {
  138.             columnNo++;
  139.             paramField = new ParameterField();
  140.             paramField.Name = "col" + columnNo.ToString();
  141.             paramDiscreteValue = new ParameterDiscreteValue();
  142.             paramDiscreteValue.Value = "";
  143.             paramField.CurrentValues.Add(paramDiscreteValue);
  144.             //Add the paramField to paramFields
  145.             paramFields.Add(paramField);
  146.         }
  147.  
  148.         crystalReportViewer1.ParameterFieldInfo = paramFields;
  149.  
  150.         query += " FROM Customer";
  151.  
  152.         return query;
  153.     }
it showing no error but crstal report is not generating

plz tel me the solution its very urgent
Jun 16 '09 #1
1 2155
tlhintoq
3,525 Expert 2GB
Have you done the basic debugging?
Put a breakpoint at line 6 and walk through the code one line at a time to see
  • where it is not behaving as you expect.
  • Confirm that *every* value is valid along the way (paths, assumptions etc.)
  • Are you sure you have permission to write to the destination servers/volumes?
  • Maybe you're getting exceptions and not seeing them since your messageboxes are commented out.
  • Confirmed that each query going out is right, and each response back is right and has content?
Jun 16 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Stephan | last post: by
1 post views Thread by Chris Neal | last post: by
13 posts views Thread by kristoff plasun | last post: by
reply views Thread by Dr. Indera | last post: by
2 posts views Thread by Mythran | last post: by
1 post views Thread by Karthic | last post: by
1 post views Thread by bthomas71chevy | last post: by
reply views Thread by Chris | last post: by
11 posts views Thread by =?Utf-8?B?cmtibmFpcg==?= | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.