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 :
- Add a data set item.
- Customize the data set to fit the data that will be retrieved from the database.
- Add a crystal reports item and link it to the previous added data set.
- 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.
- 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 .
- Bind the data table with the data set, and the crystal report viewer with a report document by using this code
DataSet1 ds = new DataSet1();
ds.Tables[0].Merge(datattable1);
rpt.Load(/*CrystalReport1.rpt path*/);
rpt.SetDataSource(ds);
crystalReportViewer1.ReportSource = rpt;
And for more details watch this video