Showing posts with label create crystal report based-on custom SQL statement C# dotnet DataSet. Show all posts
Showing posts with label create crystal report based-on custom SQL statement C# dotnet DataSet. Show all posts

Monday, April 16, 2012

How to create a crystal report based on a custom SQL statement

Welcome everybody

In this article i will show you how to create a crystal report that based on a custom SQL statement; you have to follow these steps after creating a new project and a sample database :


  1. Add a data set item.
  2. Customize the data set to fit the data that will be retrieved from the database. 
  3. Add a crystal reports item and link it to the previous added data set.
  4. Add a crystal report viewer component to the form which you want to view the report and link it to the previous added crystal report.
  5. Find a way to program a function that returns a data table, and be sure that the columns names and the columns data types in the data table are same as these in the data set .
  6. Bind the data table with the data set, and the crystal report viewer with a report document by using this code
            ReportDocument rpt = new ReportDocument();
            DataSet1 ds = new DataSet1();
            ds.Tables[0].Merge(datattable1);
            rpt.Load(/*CrystalReport1.rpt path*/);
            rpt.SetDataSource(ds);
            crystalReportViewer1.ReportSource = rpt;

note: put the previous code in form load region.

And for more details watch this video

good luck