473,388 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 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 2281
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

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

Similar topics

1
by: Stephan | last post by:
Hi, I'm using Visual Studio 2003 (C#) with the integrated Crystal Report software and have the following question: How can I assign a value (string) to an unbound (string) field in Crystal...
1
by: Chris Neal | last post by:
I recenetly purchased VB.net standard and in the box was a card saying that it included crystal reports (as it always used to) but I cannot find CR in the templates or in the toolbox. Can anyone...
13
by: kristoff plasun | last post by:
I have a problem with a C++ DCOM application that prints Crystal Reports with data from Oracle. The SQL query is relatively complex but when the report is printed from the Crystal Reports...
0
by: Dr. Indera | last post by:
hello, i previously posted the questions below on several crystal reports newsgroups, including the one for the company that makes crystal reports, but never got an answer, so i'm hoping that...
2
by: Mythran | last post by:
In .Net, how can I go about and set a Crystal Reports namespace? Right now they use the Root Namespace (VB) from the project. How can I extend the namespace for a single report (which will be set...
1
by: Karthic | last post by:
When i right click on the .rpt file in the VS 2003, i see a property printer setting. It says "No printer" on the top and there is option to select printer and paper settings etc.. I want to...
1
by: bthomas71chevy | last post by:
I have just setup a WebServer and all the applications work fine, but when every any of the applications try to generate a Crystal Report the page errors out. "File or assembly name...
0
by: Chris | last post by:
I have the following situation in a VB.Net App I am working on: 1.)A report created in VS.Net 2003 using the CR.Net component of VS 2003. 2.)The datasource for the report is a Stored Proc in a...
11
by: =?Utf-8?B?cmtibmFpcg==?= | last post by:
How can I stop receiving this message while calling a crystal report? "The report you requested requires further information." Thanks
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.